-
Notifications
You must be signed in to change notification settings - Fork 0
/
Max.java
61 lines (46 loc) · 1.29 KB
/
Max.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
import java.util.Scanner;
public class Max
{
public static void main(String [] args)
{
Scanner keyboard = new Scanner(System.in);
int num_of_salespersons;
System.out.print("Enter the number of sales persons: ");
num_of_salespersons = keyboard.nextInt();
if(num_of_salespersons == 0)
{
System.out.println("\nSince salespersons = " + num_of_salespersons + ", there are no winners of this contest.");
}
else
{
int num_of_units_sold = 0;
int largest_value = 0;
int i;
int winner = 0;
int tied_value = 0;
int tied_winner = 0;
for(i = 1; i <= num_of_salespersons; i++)
{
System.out.print("Enter the number of units sold for sales person #" + i + ": ");
num_of_units_sold = keyboard.nextInt();
if(num_of_units_sold > largest_value)
{
tied_value = largest_value;
tied_winner = winner;
winner = i;
largest_value = num_of_units_sold;
}
else if(num_of_units_sold > tied_value)
{
tied_value = num_of_units_sold;
tied_winner = i;
}
}
System.out.println("\nThe winner of the sales contest: Sales Person #" + winner + ". \nNumber of units sold: " + largest_value);
if(tied_value == largest_value)
{
System.out.println("\nThe 2nd winner of the sales contest: Sales Person #" + tied_winner + ". \nNumber of units sold: " + tied_value);
}
}
}
}