File tree 8 files changed +256
-0
lines changed
8 files changed +256
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ public class Demo2 {
3
+ public static void main (String args [])
4
+ {
5
+ int x =10 ;
6
+ if (x ==1 )
7
+ {
8
+ System .out .println ("True" );
9
+ }
10
+ else
11
+ {
12
+ System .out .println ("False" );
13
+ }
14
+ int y =90 ;
15
+ if (y >=80 )
16
+ {
17
+ System .out .println ("A" );
18
+ }
19
+ if (y >=60 &&y <80 )
20
+ {
21
+ System .out .println ("B" );
22
+ }
23
+ if (y >=40 &&y <60 )
24
+ {
25
+ System .out .println ("C" );
26
+ }
27
+ if (y <40 )
28
+ {
29
+ System .out .println ("D" );
30
+ }
31
+ }
32
+ }
Original file line number Diff line number Diff line change
1
+ public class Demo3
2
+ {
3
+ public static void main (String args [])
4
+ {
5
+ int a =10 ;
6
+ if (a >0 )
7
+ {
8
+ System .out .println ("positive" );
9
+ }
10
+ else
11
+ {
12
+ System .out .println ("negative" );
13
+ }
14
+ //one more case when a=0;
15
+ int b =7 ;
16
+ if (b %2 ==0 )
17
+ {
18
+ System .out .println ("even" );
19
+ }
20
+ else
21
+ {
22
+ System .out .println ("odd" );
23
+ }
24
+ }
25
+ }
Original file line number Diff line number Diff line change
1
+ import java .util .*;
2
+ public class Demo4
3
+ {
4
+ public static void main (String args [])
5
+ {
6
+ Scanner sc =new Scanner (System .in );
7
+ int m =sc .nextInt ();
8
+
9
+ switch (m %7 )
10
+ {
11
+ case 1 :
12
+ System .out .println ("Sunday" );
13
+ break ;
14
+ case 2 :
15
+ System .out .println ("Monday" );
16
+ break ;
17
+ case 3 :
18
+ System .out .println ("Tuesday" );
19
+ break ;
20
+ case 4 :
21
+ System .out .println ("Wednesday" );
22
+ break ;
23
+ case 5 :
24
+ System .out .println ("Thursday" );
25
+ break ;
26
+ case 6 :
27
+ System .out .println ("Friday" );
28
+ break ;
29
+ case 0 :
30
+ System .out .println ("Saturday" );
31
+ break ;
32
+
33
+ }
34
+ }
35
+ }
Original file line number Diff line number Diff line change
1
+ public class Demo5 {
2
+ public static void main (String args [])
3
+ {
4
+ int x =1 ;
5
+ String str ;
6
+ str =(x >10 )?"True" :"False" ;
7
+ System .out .println (str );
8
+ }
9
+ }
Original file line number Diff line number Diff line change
1
+ class A {
2
+ public void show ()
3
+ {
4
+
5
+ System .out .println ("Parent class method" );
6
+ }
7
+ }
8
+
9
+ class B extends A
10
+ {
11
+ public void show ()
12
+ {
13
+ super .show ();
14
+ System .out .println ("B class method" );
15
+ }
16
+ // public B()
17
+ // {
18
+ // super();
19
+ // }
20
+
21
+ }
22
+ class C extends B
23
+ {
24
+ public void show ()
25
+ {
26
+ super .show ();
27
+ System .out .println ("C class method" );
28
+ }
29
+ }
30
+ public class Inherit {
31
+ public static void main (String args [])
32
+ {
33
+ C obj =new C ();
34
+ obj .show ();
35
+ }
36
+ }
Original file line number Diff line number Diff line change
1
+ class Student {
2
+ private int id =102 ; //Instance variable
3
+ private String name ;
4
+ // char c;
5
+ public void setId (int id )
6
+ {
7
+ this .id =id ;
8
+ }
9
+ public int getId ()
10
+ {
11
+ return this .id ;
12
+ }
13
+ public void setname (String name )
14
+ {
15
+ this .name =name ;
16
+ }
17
+ public String getname ()
18
+ {
19
+ return this .name ;
20
+ }
21
+ // public void show()
22
+ // {
23
+ // int id=101; //local variable
24
+ // System.out.println(this.id);
25
+ // System.out.println(id);
26
+ //}
27
+ }
28
+
29
+ public class inh {
30
+
31
+ public static void main (String args [])
32
+ {
33
+ Student obj =new Student (); // here new student is an object not obj new for asking class and student is constructor of class
34
+ // obj.id=101;
35
+ // obj.name="jatt";
36
+ //// obj.c;
37
+ //// System.out.println(obj.id);
38
+ // obj.show();
39
+ // System.out.println(obj.name);
40
+ // System.out.println(obj.c);
41
+
42
+ obj .setId (101 );
43
+ obj .setname ("johar" );
44
+ int x =obj .getId ();
45
+ String y =obj .getname ();
46
+ System .out .println (x );
47
+ System .out .println (y );
48
+ }
49
+ }
50
+
51
+ // to acess private use getter and setter methods
52
+
53
+
54
+
55
+ //byte short int long =01
56
+ //
57
+ //float double=0.0
58
+ //
59
+ //char='\u0000'
60
+
Original file line number Diff line number Diff line change
1
+ import java .util .*;
2
+
3
+ class insertionSort
4
+ {
5
+ public static void main (String [] args ) {
6
+
7
+ Scanner sc =new Scanner (System .in );
8
+ int n =sc .nextInt ();
9
+ int arr []=new int [n ];
10
+ for (int i =0 ;i <n ;i ++)
11
+ {
12
+ arr [i ]=sc .nextInt ();
13
+ }
14
+
15
+ for (int i =1 ;i <n ;i ++)
16
+ {
17
+ int key =arr [i ];
18
+ int j =i -1 ;
19
+
20
+ while (j >=0 && arr [j ]>key )
21
+ {
22
+ arr [j +1 ]=arr [j ];
23
+ j --;
24
+ }
25
+ arr [j +1 ]=key ;
26
+ }
27
+ for (int i =0 ;i <n ;i ++)
28
+ {
29
+ System .out .print (arr [i ]+" " );
30
+ }
31
+ }
32
+ }
Original file line number Diff line number Diff line change
1
+ import java .util .*;
2
+ public class primeno
3
+ {
4
+ public static void main (String args [])
5
+ {
6
+ Scanner sc =new Scanner (System .in );
7
+ int x =sc .nextInt ();
8
+
9
+ for (int n =2 ;n <x ;n ++)
10
+ {
11
+ int flag =0 ;
12
+ for (int i =2 ;i <n ;i ++)
13
+ {
14
+ if (n %i ==0 )
15
+ {
16
+ flag =1 ;
17
+ break ;
18
+ }
19
+ }
20
+ if (flag ==0 )
21
+ {
22
+ System .out .println (n );
23
+ }
24
+
25
+ }
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments