150k views
2 votes
.Write an if-else statement for the following:

If userTickets is greater than 5, execute awardPoints = 10. Else, execute awardPoints = userTickets.

Ex: If userTickets is 14, then awardPoints = 10.

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(); // Program will be tested with values: 4, 5, 6, 7.

/* Your solution goes here */

System.out.println(awardPoints);
}
}

2 Answers

3 votes

Answer:if (userTickets < 7 ) {

awardPoints = 1;

}

else {

awardPoints = userTickets;

}

Step-by-step explanation:

.Write an if-else statement for the following: If userTickets is greater than 5, execute-example-1
User Tymik
by
8.5k points
2 votes

Answer:

Solution part of the question:

if(userTickets>5) //compare the value of userTickets with 5.

awardPoints = 10; // assign the 10 value to the award point

else

awardPoints=userTickets;// assign the userticket value to the awardpoint.

Output:

For the input 4 the output is 4.

For the input 5 the output is 5.

For the input 6 the output is 10.

For the input 7 the output is 10.

Step-by-step explanation:

All the other part of the program is given on the question so here only if-else statement is given on the answer part. Which is pasted at the place of "/* Your solution goes here */" and the user can get the right answer.

  • In the "if" statement the value of "userTickets" variable is get compared by 5 and if it is greater than 5 than variable "awardpoint" assigns the '10' value.
  • Otherwise, with the help of "else" statement "userticket" variables value (which is the input value for the program) assign to the "awardpoint" variable.
User Yihangho
by
8.1k points
Welcome to QAmmunity.org, where you can ask questions and receive answers from other members of our community.