-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBulb.java
More file actions
48 lines (41 loc) · 1.11 KB
/
Bulb.java
File metadata and controls
48 lines (41 loc) · 1.11 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
package accentureQ;
import java.util.Scanner;
//public class Bulb {
//
// public static void main(String[] args) {
// Scanner sc = new Scanner(System.in);
// System.out.print("Enter number: ");
// int n = sc.nextInt();
// int arr[] = new int[n];
//
// // Initialize all bulbs as on (1)
// for (int i = 0; i < n; i++) {
// arr[i] = 1;
// }
//
// // Perform bulb toggling rounds
// for (int i = 2; i <= n; i++) {
// for (int j = i - 1; j < n; j += i) {
// arr[j] = 1 - arr[j]; // Toggle the bulb
// }
// }
//
// int count = 0;
// for (int i = 0; i < n; i++) {
// if (arr[i] == 1) {
// count++;
// }
// }
//
// System.out.println(count);
// }
//}
// 2nd Method
public class Bulb {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number: ");
int n = sc.nextInt();
System.out.println((int)Math.sqrt(n));
}
}