Sie sind auf Seite 1von 2

Class ROTN 1/2

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

Jul 15, 2018 11:28:15 AM


Class ROTN (continued) 2/2

48 }
49 }
50 }//end of for-loop
51 }//end of main()
52 }//end of class

Jul 15, 2018 11:28:15 AM

Das könnte Ihnen auch gefallen