-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBenjaminBulb.java
More file actions
25 lines (24 loc) · 828 Bytes
/
BenjaminBulb.java
File metadata and controls
25 lines (24 loc) · 828 Bytes
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
// Banjamin bulb
// Problem: Given n bulbs that are initially off, you toggle the state of the bulbs in a specific pattern.
import java.util.Scanner;
public class BenjaminBulb {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of bulbs: ");
int bulbs = sc.nextInt();
int count = 0;
System.out.println("The number of bulbs that are on after toggling is: ");
for(int i = 1; i <= bulbs; i++) {
for(int j = 1; j <= i; j++) {
if(i % j == 0) {
count++;
}
}
if(count % 2 != 0) {
System.out.print(i + " ");
}
count = 0;
}
sc.close();
}
}