+ 3
I tried but its not solving
You are trying to send a secret message, and you've decided to encode it by replacing every letter in your message with its corresponding letter in a backwards version of the alphabet. What do your messages look like? Task: Create a program that replaces each letter in a message with its corresponding letter in a backwards version of the English alphabet. Input Format: A string of your message in its normal form. Output Format: A string of your message once you have encoded it (all lower case). Sample Input: Hello World Sample Output: svool dliow
6 Antworten
+ 2
Try this one:
import java.util.Scanner;
public class Program{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String input=sc.nextLine();
//System.out.println("you entered :"+input);
char[] ch=input.toCharArray();
for(int i=0;i<ch.length;i++){
if(Character.isLetter(ch[i])) {
if(ch[i]>=97 && ch[i]<=122)
ch[i]=(char)(122-(int)ch[i]+97);
else if(ch[i]>=65 && ch[i]<=90)
ch[i]=(char)(90-(int)ch[i]+65);
}
}
System.out.println("" +new String(ch).toLowerCase());
}
}
+ 3
import java.util.Scanner ;
public class Program
{
public static void main(String[] args)
{
Scanner sc = new Scanner (System.in) ;
String input=sc.nextLine();
System.out.println ("You entered :"+input);
char[] ch=input.toCharArray();
for(int i=0;i<ch.length;i++)
{
if(Character.isLatter(ch[i]))
{
if(ch[i]>=97 && ch[i]<=122)
ch[i]=(char)(122-(int)ch[i]+97);
else if(ch[i]>=65 && ch[i]<=90)
ch[i]=(char)(90-(int)ch[i]+65);
}
}
String output =new String (ch);
System.out.println ("The secret massage is :"+output.toLowerCase());
}
}
Can you ask me what is wrong in hare ?
+ 2
Kartik Singh ur code is right just put // before first println statement or remove statement
+ 2
Try this one:
Code for #Java
import java.util.Scanner;
public class Program{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String input=sc.nextLine();
char[] ch=input.toCharArray();
for(int i=0;i<ch.length;i++){
if(Character.isLetter(ch[i])) {
if(ch[i]>=97 && ch[i]<=122)
ch[i]=(char)(122-(int)ch[i]+97);
else if(ch[i]>=65 && ch[i]<=90)
ch[i]=(char)(90-(int)ch[i]+65);
}
}
System.out.println("" +new String(ch).toLowerCase());
}
}
0
You have a typo
Character.isLetter()
Learn how to debug your code. If you run it in the code playground, the error message will point you to this line.
0
Thanks