-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWordTower.java
More file actions
45 lines (39 loc) · 1.41 KB
/
Copy pathWordTower.java
File metadata and controls
45 lines (39 loc) · 1.41 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
package lab_assignment_1;
import java.util.Scanner;
public class WordTower{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of 'B' blocks required : ");
int N=sc.nextInt();
if(!(1<=N && N<=2024)){
System.out.println("Invalid Input");
}else{
System.out.println("A");
for(int i=0;i<=N;i++){
System.out.println("B");
}
System.out.println("C");
System.out.println("D");
} }
}
/*public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of 'B' blocks (N): ");
int N = sc.nextInt();
if (!(1 <= N && N <= 2024)) {
System.out.println("Invalid input. N should be a positive integer between 1 and 2024.");
} else {
StringBuilder wordTowerSequence = new StringBuilder();
wordTowerSequence.append('A');
for (int i = 0; i < N; i++) {
wordTowerSequence.append('B');
}
wordTowerSequence.append('C');
wordTowerSequence.append('D');
// Convert StringBuilder to String and display the constructed Word Tower
String wordTower = wordTowerSequence.toString();
System.out.println("Word Tower of height " + N + ": " + wordTower);
}
// Close the scanner
sc.close();
}*/