-
Notifications
You must be signed in to change notification settings - Fork 0
/
HelloWorld.java
105 lines (84 loc) · 2.77 KB
/
HelloWorld.java
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
//https://www.codewars.com/kata/55bf01e5a717a0d57e0000ec/train/java
import java.util.Scanner;
/*
Name: Ang, Julienne S.
Date: August 15, 2022
Problem:
Write a program that displays "Hello World!" on the output screen.
*/
public class HelloWorld {
public static void main(String[] args){
Scanner kbd = new Scanner(System.in);
int num = getNumber(kbd);
String digitString = getDigits(num);
int result = getResult(num, digitString);
System.out.print(result);
} // end of main method
private static String getDigits(int num) {
return String.valueOf(num);
}
private static int getNumber(Scanner kbd) {
do {
try {
System.out.print("Enter the number: ");
int num = kbd.nextInt();
if (num > 11){
return num;
}
} catch (java.util.InputMismatchException e) {
System.out.println("Invalid input. Please input a positive integer more than 10");
}
} while (true);
}
private static int getResult(int num, String digitString) {
int digits = Integer.parseInt(digitString);
int[] number = new int[digits];
int resultedNum = 1;
int count = 0;
if (num >= 100){
int digit1 = num/100;
num %= 100;
int digit2 = num/10;
num %= 10;
int digit3 = num/10;
num %= 10;
number[0] = digit1;
number[1] = digit1;
number[2] = digit1;
} else if (num >= 11){
int digit2 = num/10;
num %= 10;
int digit3 = num/10;
num %= 10;
number[0] = digit2;
number[1] = digit3;
}
while (true){
for (int i : number){
resultedNum *= i;
if (resultedNum >= 100){
int digit1 = num/100;
num %= 100;
int digit2 = num/10;
num %= 10;
int digit3 = num/10;
num %= 10;
number[0] = digit1;
number[1] = digit1;
number[2] = digit1;
} else if (resultedNum >= 11){
int digit2 = num/10;
num %= 10;
int digit3 = num/10;
num %= 10;
number[0] = digit2;
number[1] = digit3;
}
count++;
if (resultedNum < 11) {
return count;
}
}
}
}
} // end of class