-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNestedLoop.java
More file actions
66 lines (59 loc) · 1.72 KB
/
Copy pathNestedLoop.java
File metadata and controls
66 lines (59 loc) · 1.72 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
package com.example.NestedLoop;
import java.util.Scanner;
public class NestedLoop {
static Scanner scanner = new Scanner(System.in);
public void aToZ(){
for (int i = 65; ;i++){
System.out.print((char)(i) + " ");
if((char)(i) == 'Z'){
System.out.println();
break;
}
}
}
public void multiplicationTable(){
for(int i = 1; i <= 12; i++){
for(int j = 1; j <= 12; j++){
System.out.print(i * j + " ");
}
System.out.println();
}
}
public void primeToZ(int n){
for (int i = 1; i <= n; i++){
boolean prime = true;
for (int j = 2; j <= (i / 2); j++){
if (i % j == 0){
prime = false;
}
}
if (prime == true){
System.out.println(i);
}
}
}
public void starX(int n){
for (int i = 1; i <= n; i++){
for (int j = 1; j <= n; j++){
if(j == i || j == n - i + 1 ) {
System.out.print("*");
}
else{
System.out.print(" ");
}
}
System.out.println();
}
}
public static void main(String[]args){
NestedLoop runner = new NestedLoop();
runner.aToZ();
runner.multiplicationTable();
System.out.println("Input a integer");
int a = scanner.nextInt();
runner.primeToZ(a);
System.out.println("Input a integer");
int b = scanner.nextInt();
runner.starX(b);
}
}