Class ROTN 1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
1/2
import java.io.*; class ROTN { public static void main()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System .in)); String s; System.out.println("\nEnter the string"); s=br.readLine(); while(s.length()<3||s.length()>100)//validation { System.out.println("Invalid. Length of the string should be i n between 3 and 100. Re-enter"); s=br.readLine(); } System.out.println("Enter the rotation magnitude" ); int n=Integer.parseInt(br.readLine()); for(int i=0;i<s.length();i++) { char ch=s.charAt(i); if(ch==' '&&s.charAt(i-1)==' ') continue; else { if(ch=='#'||ch=='@'||ch=='$')//again validation! { int c=(int)ch; c=c-2; ch=(char)c; System.out.print(ch); } else if(ch<65||ch>122) System.out.print(ch); if(Character.isUpperCase(ch)==true) { int c=(int)ch; c=c+n; if(c>90)//conversion c=c-26; System.out.print((char)c); } else if(Character.isLowerCase(ch)==true) { int c=(int)ch; c=c+n; if(c>122) c=c-26; System.out.print((char)c); Jul 15, 2018 11:28:15 AM
Class ROTN (continued) 48 49 50 51 52
2/2
} } }//end of for-loop }//end of main() }//end of class
Jul 15, 2018 11:28:15 AM