File tree Expand file tree Collapse file tree 3 files changed +170
-0
lines changed Expand file tree Collapse file tree 3 files changed +170
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .*;
2
+ class CaeserCipher
3
+ {
4
+ String s ; //declaration
5
+ public CaeserCipher () //default constructor to initialise s
6
+ {
7
+ s ="" ;
8
+ }
9
+ void input () //input text
10
+ {
11
+ Scanner sc =new Scanner (System .in );
12
+ System .out .println ("enter text" );
13
+ s =sc .nextLine ();
14
+ }
15
+ void encrpyt ()
16
+ {
17
+ int L ; //declaration
18
+ char ch ;
19
+ String s1 ="" ;
20
+ L =s .length ();
21
+ if (L >3 && L <100 )
22
+ {
23
+ for (int i =0 ;i <L ;i ++)
24
+ {
25
+ ch =s .charAt (i ); //character extraction
26
+ if (ch >='A' && ch <='M' || ch >='a' && ch <='m' )
27
+ s1 =s1 +(char )(ch +13 );
28
+ else
29
+ if (ch >='N' && ch <='Z' || ch >='n' && ch <='z' )
30
+ s1 =s1 +(char )(ch -13 );
31
+ else
32
+ s1 =s1 +ch ;
33
+ }
34
+ System .out .println ("Encrypted text=" +s1 ); //printing
35
+ }
36
+ else
37
+ System .out .print ("INVALID LENGTH" );
38
+ }
39
+ public static void main ()
40
+ {
41
+ CaeserCipher ob =new CaeserCipher (); //creating object ob
42
+ ob .input (); //calling function
43
+ ob .encrpyt (); //calling function
44
+ }
45
+ }
46
+
47
+
48
+
49
+
50
+
51
+
Original file line number Diff line number Diff line change
1
+ import java .util .*;
2
+ class Goldbach
3
+ {
4
+ int N ; //declaration
5
+ public Goldbach () //default constructor to initialise N
6
+ {
7
+ N =0 ;
8
+ }
9
+ void input () //to input N
10
+ {
11
+ Scanner sc =new Scanner (System .in );
12
+ System .out .println ("Enter a number" );
13
+ N =sc .nextInt ();
14
+ }
15
+ int prime (int n ) //to check for prime
16
+ {
17
+ int c =0 ;
18
+ for (int i =1 ;i <=n ;i ++)
19
+ {
20
+ if (n %i ==0 )
21
+ c ++;
22
+ }
23
+ return c ;
24
+ }
25
+ void sum ()
26
+ {
27
+ if (N %2 ==0 )
28
+ {
29
+ if (N >9 && N <50 )
30
+ {
31
+ for (int i =3 ;i <=N /2 ;i ++)
32
+ {
33
+ for (int j =3 ;j <=N ;j ++)
34
+ {
35
+ if (i +j ==N && prime (i )==2 && prime (j )==2 )
36
+ {
37
+ System .out .println ("Prime pairs are=" +i +" " +j ); //printing the odd prime pairs
38
+ }
39
+ }
40
+ }
41
+ }
42
+ else
43
+ System .out .print ("Invalid input,Number out of range" );
44
+ }
45
+ else
46
+ System .out .print ("Invalid input,number is Odd" );
47
+ }
48
+ public static void main ()
49
+ {
50
+ Goldbach ob =new Goldbach (); //creating object
51
+ ob .input (); //calling
52
+ ob .sum (); //calling
53
+ }
54
+ }
Original file line number Diff line number Diff line change
1
+ import java .util .*;
2
+ class PrimeAdam
3
+ {
4
+ int m ,n ; //declaration
5
+ public PrimeAdam ()
6
+ {
7
+ m =n =0 ;
8
+ }
9
+ void input () //input lower and upper range
10
+ {
11
+ Scanner sc =new Scanner (System .in );
12
+ System .out .println ("Enter m and n" );
13
+ m =sc .nextInt ();
14
+ n =sc .nextInt ();
15
+ }
16
+ int prime (int no ) //check for prime
17
+ {
18
+ int c =0 ; //declaration
19
+ for (int i =1 ;i <=no ;i ++)
20
+ {
21
+ if (no %i ==0 )
22
+ c ++;
23
+ }
24
+ return c ;
25
+ }
26
+ int adam (int no ) //check for adam
27
+ {
28
+ int s =0 ,p =1 ,s1 =0 ; //declaration
29
+ while (no >0 )
30
+ {
31
+ s =s *10 +(no %10 );
32
+ no =no /10 ;
33
+ }
34
+ p =s *s ;
35
+ while (p >0 )
36
+ {
37
+ s1 =s1 *10 +(p %10 );
38
+ p =p /10 ;
39
+ }
40
+ return s1 ;
41
+ }
42
+ void print () //printing prime-adam numbers between m and n
43
+ {
44
+ int c =0 ; //declaration
45
+ for (int i =m ;i <=n ;i ++)
46
+ {
47
+ if ((prime (i )==2 ) && ((adam (i ))==(i *i )))
48
+ {
49
+ System .out .print (i +" " );
50
+ c ++;
51
+ }
52
+ }
53
+ System .out .println ();
54
+ System .out .print ("FREQUENCY OF PRIME-ADAM INTEGERS IS=" +c );
55
+ }
56
+ public static void main ()
57
+ {
58
+ PrimeAdam ob =new PrimeAdam (); //creating object ob
59
+ ob .input (); //calling function
60
+ ob .print (); //calling function
61
+ }
62
+ }
63
+
64
+
65
+
You can’t perform that action at this time.
0 commit comments