Write an if-else statement for the following: If userTickets is less than 8, execute awardPoints = 1. Else, execute awardPoints = userTickets. Ex: If userTickets is 3, then awardPoints = 1.
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
import java.util.Scanner;
public class TicketCounter {
public static void main (String [] args) {
int awardPoints;
int userTickets;
Scanner scnr = new Scanner(System.in);
userTickets = scnr.nextInt(); //
if (userTickets < 8) {
awardPoints = 1;
System.out.println(awardPoints);
}
else {
System.out.println(awardPoints);
}
}
![zy Section 2.1 - CS 226T: Java Progra X bHome | bartleby
✰ learn.zybooks.com/zybook/CS226-2204A-03-2204A/chapter/2/section/1
CTU Class Homepage.
=zyBooks My library > CS 226T: Java Programming home > 2.1: If-else
CHALLENGE
ACTIVITY
422784.2543518.qx3zqy7
Jump to level 1
Write an if-else statement for the following:
If userTickets is less than 8, execute award Points = 1. Else, execute award Points = userTickets.
Ex: If userTickets is 3, then award Points = 1.
1 import java.util.Scanner;
2
3 public class TicketCounter {
4
5
6
8
9
10
11
12
13
14
15
16
17
18
19
20
21 }
2.1.3: Basic if-else.
Check
public static void main (String [] args) {
}
}
int awardpoints;
int userTickets;
Scanner scnr = new Scanner(System.in);
userTickets = scnr.nextInt(); // Program will be tested with values: 5, 6, 7, 8.
if (userTickets < 8) {
award Points = 1;
System.out.println(award Points);
else {
awardpoints = award Points * userTickets;
System.out.println(award Points);
Try again
1
zyBooks catalog
couruun.
D-D~
? Help/FAQ
Stacey Queen
X
:
7:23 AM
8/16/2022](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F788fc729-a951-45c4-9909-47eea7bbf82f%2F8409c4e2-19cc-4b90-8f62-cc9420ecc884%2Fvhnq5qr_processed.png&w=3840&q=75)

Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images









