Sovi.AI - AI Math Tutor

Scan to solve math questions

QUESTION IMAGE

jump to level 1 write an if - else statement for the following. if user…

Question

jump to level 1
write an if - else statement for the following.
if usertickets is not equal to 8, execute awardpoints = 10. else, execute awardpoints = usertickets.
ex. if usertickets is 14, then awardpoints = 10.
1 import java.util.scanner;
2
3 public class ticketcounter {
4 public static void main (string args) {
5 int awardpoints;
6 int usertickets;
7
8 scanner scnr = new scanner(system.in);
9 usertickets = scnr.nextint(); // program will be tested with values: 6, 7, 8, 9,
10
11 code here
12
13 system.out.println(awardpoints);
14 }
15 }

Explanation:

Step1: Check if userTickets ≠ 8

if (userTickets != 8) {

Step2: Assign 10 to awardPoints

    awardPoints = 10;

Step3: Handle else case (userTickets = 8)

} else {
    awardPoints = userTickets;
}

Answer:

The completed code segment to insert at "code here" is:

if (userTickets != 8) {
    awardPoints = 10;
} else {
    awardPoints = userTickets;
}

When run with test values:

  • For 6, 7, 9: outputs 10
  • For 8: outputs 8