-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwhile_loop_example.java
More file actions
111 lines (85 loc) · 2.69 KB
/
Copy pathwhile_loop_example.java
File metadata and controls
111 lines (85 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import java.util.Scanner;
public class while_loop_example {
public static void main(String[] args) {
// int i=1;
// while(i<=25){
// System.out.println("Aditya");
// i=i+1;
// }
// program for input from user and get and get sum of first n natural numbers
// Scanner s= new Scanner(System.in);
// int n= s.nextInt();
// int sum=0;
// int i =1;
// while(i<=n){
// sum= sum+i;
// i=i+1;
// }
// System.out.println(sum);
// taking input from user and only printing out odd number skiping even number
// Scanner s= new Scanner(System.in);
// int n= s.nextInt();
// int i=1;
// while(i<=n){
// if(i%2==0)
// System.out.println(" ");
// else
// System.out.println(i);
// i++;
// }
// taking input from the user getting power
// Scanner s= new Scanner(System.in);
// int n= s.nextInt();
// int power= s.nextInt();
// int i=1;
// int ans=1;
// while (i<=power) {
// ans=ans*n;
// i++;
// }
// System.out.println(ans);
// find number of digits in the given number by logic of dividing number by 10
// Scanner s= new Scanner(System.in);
// int n=s.nextInt();
// int count=0;
// while (n>0){
// n=n/10;
// count++;
// }
// System.out.println("number of digit in the given number "+count);
// getting sum of number entered
// Scanner s = new Scanner(System.in);
// int n = s.nextInt();
// int sum = 0;
// while (n > 0) {
// sum = sum + n % 10;
// n = n / 10;
// }
// System.out.println(sum);
// finding factors of number entered by user
// Scanner s = new Scanner(System.in);
// int n = s.nextInt();
// int factors = 2;
// while (factors < n) {
// if (n % factors == 0) {
// System.out.println(factors);
// }
// factors++;
// }
// to check whether the number is prime or not
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int i = 2;
while (i < n) {
if (n % i == 0) {
System.out.println("your number is composite");
return ;
// stops the execution of program
// if we use break it will only exit us out of the loop
// if we use continue it will go back to starting of the loop
}
i++;
}
System.out.println("number is prime " + n);
}
}