-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTask03.java
More file actions
108 lines (81 loc) · 2.53 KB
/
Task03.java
File metadata and controls
108 lines (81 loc) · 2.53 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import java.util.Scanner;
public class Task03 {
public static void main(String[] args) {
// Problem 1
Scanner scan = new Scanner(System.in);
int number = scan.nextInt();
int first = number;
int times = 0;
int biggest = 0;
int last = 0;
while (number != 0) {
if (first == number)
times++;
else {
if (biggest <= times) {
biggest = times;
last = first;
}
first = number;
times = 1;
}
number = scan.nextInt();
}
if (biggest <= times) {
biggest = times;
last = first;
}
System.out.println(biggest + " times " + last);
// Problem 2
System.out.println("Enter n to triangle: ");
int n = scan.nextInt();
int space = n;
for (int i = 0; i < n; i += 2) {
for (int j = 0; j < i; j++)
System.out.print(" ");
for (int k = 0; k < space; k++)
System.out.print("* ");
System.out.println();
space -= 2;
}
// Problem 3
System.out.println("-------------------------------------------------------");
System.out.println("Enter wide and high to quadliteral: ");
int wide = scan.nextInt();
int high = scan.nextInt();
for (int i = 0; i < high; i++) {
for (int j = 0; j < wide; j++) {
if ((i == 0) || (i == high - 1) || (j == 0) || (j == wide - 1))
System.out.print("*");
else
System.out.print(" ");
}
System.out.print("\n");
}
// Problem 4
System.out.println("Enter a number: ");
int num1 = scan.nextInt();
System.out.println("One more please: ");
int num2 = scan.nextInt();
int gcd;
while (num1 != num2) {
if (num1 > num2) {
num1 -= num2;
} else {
num2 -= num1;
}
}
gcd = num1;
System.out.println(gcd);
// Problem 5
System.out.println("Enter two numbers : ");
first = scan.nextInt();
int second = scan.nextInt();
for (int i = 1; i <= first; i++) {
for (int j = 1; j <= second; j++) {
System.out.print((i * j) + "\t");
}
System.out.println();
}
}
}