Skip to content

Commit c516406

Browse files
committed
1
1 parent 3c92bc0 commit c516406

File tree

4 files changed

+75
-3
lines changed

4 files changed

+75
-3
lines changed

for_loop/Project_program2.java

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
}

for_loop/Project_program3.java

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

for_loop/Project_program5.java

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

switch_case/Project_Program_1.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ public static void main(String[] args) {
1515
switch(ch)
1616
{
1717
case 1: System.out.println("Enter the sides of the triangle");
18-
System.out.print("Side 1 ");
18+
System.out.print("Side 1: ");
1919
a = x.nextDouble();
20-
System.out.print("\n"+"Side 2 ");
20+
System.out.print("Side 2: ");
2121
b = x.nextDouble();
22-
System.out.print("\n"+"Side 3 ");
22+
System.out.print("Side 3: ");
2323
c = x.nextDouble();
2424

2525
s = (a+b+c)/2;

0 commit comments

Comments
 (0)