File tree 4 files changed +75
-3
lines changed
4 files changed +75
-3
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .Scanner ;
2
+
3
+ public class Project_program2
4
+ {
5
+ public static void main (String [] args ) {
6
+ Scanner x = new Scanner (System .in );
7
+ int ch ,i ,s =0 ;
8
+ System .out .println ("Enter choice, 1 for the sum of the first 20 natural" +
9
+ " numbers and 2 to find the sum of the series'a^0-a^1.. n terms'" );
10
+ ch = x .nextInt ();
11
+ switch (ch )
12
+ {
13
+ case 1 :
14
+ x .close ();
15
+
16
+ for (i =1 ;i <=20 ;i ++)
17
+ {
18
+ s = s +i ;
19
+ }
20
+ System .out .println (s );
21
+ break ;
22
+
23
+ case 2 :
24
+ System .out .println ("Enter the number" );
25
+ int a = x .nextInt ();
26
+ System .out .println ("Enter the number of total terms to be iterated" );
27
+ int n = x .nextInt ();
28
+ x .close ();
29
+ for (i =0 ;i <=n -1 ;i +=1 )
30
+ {
31
+ s = s + (int )Math .pow (-a ,i );
32
+ }
33
+ System .out .println (s );
34
+ break ;
35
+
36
+ default : System .out .println ("Error" );
37
+ x .close ();
38
+ }
39
+ }
40
+ }
Original file line number Diff line number Diff line change
1
+ import java .util .Scanner ;
2
+
3
+ public class Project_program3 {
4
+ public static void main (String [] args ) {
5
+ Scanner x = new Scanner (System .in );
6
+ int i ,n ,f =0 ;
7
+ System .out .println ("Enter a numer to check whether its prime or composites" );
8
+ n = x .nextInt ();
9
+
10
+ for (i =2 ;i <=n /2 ;i ++) if (n %i ==0 ) f +=1 ;
11
+ if (f ==0 ) System .out .println ("Prime" );
12
+ else System .out .println ("Composite" );
13
+ x .close ();
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ import java .util .Scanner ;
2
+ public class Project_program5 {
3
+ public static void main (String args []){
4
+ int a , b , i , hcf = 0 ;
5
+ Scanner sc = new Scanner (System .in );
6
+ System .out .println ("Enter first number :: " );
7
+ a = sc .nextInt ();
8
+ System .out .println ("Enter second number :: " );
9
+ b = sc .nextInt ();
10
+
11
+ for (i = 1 ; i <= a || i <= b ; i ++) {
12
+ if ( a %i == 0 && b %i == 0 )
13
+ hcf = i ;
14
+ }
15
+ System .out .println ("HCF of given two numbers is ::" +hcf );
16
+ }
17
+ }
Original file line number Diff line number Diff line change @@ -15,11 +15,11 @@ public static void main(String[] args) {
15
15
switch (ch )
16
16
{
17
17
case 1 : System .out .println ("Enter the sides of the triangle" );
18
- System .out .print ("Side 1 " );
18
+ System .out .print ("Side 1: " );
19
19
a = x .nextDouble ();
20
- System .out .print ("\n " + " Side 2 " );
20
+ System .out .print ("Side 2: " );
21
21
b = x .nextDouble ();
22
- System .out .print ("\n " + " Side 3 " );
22
+ System .out .print ("Side 3: " );
23
23
c = x .nextDouble ();
24
24
25
25
s = (a +b +c )/2 ;
You can’t perform that action at this time.
0 commit comments