I tried but its not solving | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

8th May 2020, 6:55 AM
Kartik Singh
Kartik Singh - avatar
6 Answers
+ 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()); } }
1st Oct 2020, 3:56 AM
MAYURI BAVISKAR
MAYURI BAVISKAR - avatar
+ 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 ?
8th May 2020, 6:56 AM
Kartik Singh
Kartik Singh - avatar
+ 2
Kartik Singh ur code is right just put // before first println statement or remove statement
1st Oct 2020, 3:58 AM
MAYURI BAVISKAR
MAYURI BAVISKAR - avatar
+ 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()); } }
1st Feb 2022, 7:56 PM
Avrian Shandy
Avrian Shandy - avatar
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.
8th May 2020, 7:15 AM
Tibor Santa
Tibor Santa - avatar
0
Thanks
1st Oct 2020, 6:18 AM
Kartik Singh
Kartik Singh - avatar