-
Notifications
You must be signed in to change notification settings - Fork 1
/
hop.java
82 lines (63 loc) · 1.22 KB
/
hop.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
package hop;
import java.util.Scanner;
public class hop {
public static void main(String[] args) {
System.out.println("Please enter the Distance");
Scanner scr = new Scanner(System.in);
try {
int question = scr.nextInt();
int rest = 0;
int hop = 0;
int count = 1;
//System.out.println("hop = " + hop + " rest = " + rest);
while(question>0) {
if(count == 1) {
if(question>8) {
hop++;
count++;
rest += 5;
question -= 8;
}
else {
hop++;
question =0;
}
}
else if(count == 2) {
if(question>5) {
hop++;
count++;
rest += 3;
question -= 5;
}
else {
hop++;
question =0;
}
}
else if(count == 3) {
if(question>2) {
hop++;
count++;
rest += 2;
question -= 2;
}
else {
hop++;
question =0;
}
}
else{
count++;
hop++;
rest += 2;
question -= 2;
}
}
System.out.println("hop count = " + hop + " Total rest = " + rest+"s");
}
catch(Exception e){
System.out.println("Please Enter a valid distance");
}
}
}