-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode 55.txt
65 lines (54 loc) · 1.96 KB
/
code 55.txt
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
/*
* Program: exam 2017 question 4
* Date: 28/5/2019
* Programmer: J.Sookha
* Description:
*/
package exam2017question4;
import java.util.Scanner;
public class exam2018question7{
static Scanner sc = new Scanner(System.in);
static int inInput, intCounter;
static int intCount1, intCount2, intCount3;
public static void main(String[] args){
intCounter = 0;
intCount1 = 0;
intCount2 = 0;
intCount3 = 0;
System.out.println("Please enter a 1, 2 or 3 for the winning player: \n" +
" (1) Novak Djokovic \n (2) Andy Murray \n (3) Roger Federer \n");
System.out.print("Enter the player number who won match " + (intCounter + 1) + ": ");
intInput = sc.nextInt();
do{
if ((intInput < 0) || (intInput > 3)){
System.out.println("You have entered an invalid selection");
System.out.print("Please enter a selection fron 1 - 3: ");
intInput = sc.nextInt();
}
}while ((intInput < 0) || (intInput > 3));
while (intInput != 0){
intCounter = intCounter + 1;
if (intInput == 1)
intCount1++;
if (intInput == 2)
intCount2++;
if (intInput == 3)
intCount3++;
System.out.print("Enter the player number who won match " + (intCounter + 1) + ": ");
intInput = sc.nextInt();
do{
if ((intInput < 0) || (intInput > 3)){
System.out.println("You have entered an invalid selection");
System.out.print("Please enter a selection fron 1 - 3: ");
intInput = sc.nextInt();
}
}while ((intInput < 0) || (intInput > 3));
}
System.out.println();
System.out.println(String.format("%20s : %20s", "NOVAK DJOKOVIC", intCount1));
System.out.println(String.format("%20s : %20s", "ANDY MURRAY", intCount2));
System.out.println(String.format("%20s : %20s", "ROGER FEDERER", intCount3));
System.out.println("------------------------------------------");
System.out.println(String.format("%20s : %20s", "GAME COUNT", (intCounter));
}
}