-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoreNestedLoops.java
More file actions
93 lines (85 loc) · 2.42 KB
/
Copy pathMoreNestedLoops.java
File metadata and controls
93 lines (85 loc) · 2.42 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
package com.example.MoreNestedLoops;
import java.util.Scanner;
import java.util.SimpleTimeZone;
public class MoreNestedLoops {
static Scanner scanner = new Scanner(System.in);
public void loopingBox(int a){
int j = 1;
int b = a;
for (int i = 1; i <= a; i++){
for (j = i; j <= b; j++){
System.out.print(j + " ");
}
for (j = 1; j <= i - 1; j++){
System.out.print(j + " ");
}
System.out.println();
}
}
public void triangle(int a){
int b = 1;
for (int i = 1; i <= a; i++){
for (int j = 1; j <= b; j++){
System.out.print("X");
}
System.out.println();
b++;
}
}
public void power(int a, int b){
int c = 1;
while(b != a){
b = b /a;
c++;
}
System.out.println(c);
}
public void diamond(int a){
int j;
int i;
int start = a;
int end = a;
for (i = 1; i < a; i++){
for (j = 1; j <= a; j++) {
if(j >= start && j <= end){
System.out.print("* ");
}
else{
System.out.print(" ");
}
}
System.out.println();
start--;
end++;
}
for (i = a; i <= a*2-1; i++){
for (j = 1; j <= a; j++) {
if(j >= start && j <= end){
System.out.print("* ");
}
else{
System.out.print(" ");
}
}
System.out.println();
start++;
end--;
}
}
public static void main(String[]args){
MoreNestedLoops runner = new MoreNestedLoops();
System.out.println("Input a integer");
int a = scanner.nextInt();
runner.loopingBox(a);
System.out.println("Input a integer");
int b = scanner.nextInt();
runner.triangle(b);
System.out.println("Input two integers");
int c = scanner.nextInt();
int d = scanner.nextInt();
runner.power(c, d);
System.out.println("Input a integer");
int e = scanner.nextInt();
runner.diamond(e);
}
}