Question

Write an if-else statement that checks patronAge. If 55 or greater, print "Senior citizen", otherwise print...

Write an if-else statement that checks patronAge. If 55 or greater, print "Senior citizen", otherwise print "Not senior citizen" (without quotes). End with newline.

import java.util.Scanner;

public class DetectSenior {
   public static void main (String [] args) {
      Scanner scnr = new Scanner(System.in);
      int patronAge;

//Solution goes here//

      patronAge = scnr.nextInt();

   }
}

Homework Answers

Answer #1
import java.util.Scanner;

public class DetectSenior {
    public static void main (String [] args) {
        Scanner scnr = new Scanner(System.in);
        int patronAge;
        
        patronAge = scnr.nextInt();

        if(patronAge >= 55){
            System.out.println("Senior citizen");
        }
        else{
            System.out.println("Not senior citizen");
        }

    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
in JAVA Write a switch statement that checks origLetter. If 'a' or 'A', print "Alpha". If...
in JAVA Write a switch statement that checks origLetter. If 'a' or 'A', print "Alpha". If 'b' or 'B', print "Beta". For any other character, print "Unknown". Use fall-through as appropriate. End with newline. import java.util.Scanner; public class ConvertToGreek { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); char origLetter; origLetter = scnr.next().charAt(0); /* Your solution goes here */ } }
Write an expression that will cause "greater or equal to -10" to print if the value...
Write an expression that will cause "greater or equal to -10" to print if the value of userNum is greater than or equal to -10. import java.util.Scanner; public class EqualityAndRelational {    public static void main (String [] args) {       int userNum;       Scanner scnr = new Scanner(System.in);       userNum = scnr.nextInt(); // Program will be tested with values: -9, -10, -11, -12.       if (//solution goes here//) {          System.out.println("greater or equal to -10");       }       else...
Write an expression that will cause "Foot or more" to print if the value of numInches...
Write an expression that will cause "Foot or more" to print if the value of numInches is greater than or equal to 12. import java.util.Scanner; public class EqualityAndRelational {    public static void main (String [] args) {       int numInches;       Scanner scnr = new Scanner(System.in);       numInches = scnr.nextInt(); // Program will be tested with values: 10, 11, 12, 13.       if (/* Your solution goes here */) {          System.out.println("Foot or more");       }       else {...
Write a for loop to print all elements in courseGrades, following each element with a space...
Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print: 7 9 11 10 10 11 9 7 Hint: Use two for loops. Second loop starts with i = courseGrades.length - 1. (Notes) IN JAVA: import java.util.Scanner; public class CourseGradePrinter { public static void main (String [] args) { Scanner scnr =...
4.9.1: Nested loops: Indent text. JAVA Print numbers 0, 1, 2, ..., userNum as shown, with...
4.9.1: Nested loops: Indent text. JAVA Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints: 0 1 2 3 Please use my template import java.util.Scanner; public class...
Write a loop that sets each array element to the sum of itself and the next...
Write a loop that sets each array element to the sum of itself and the next element, except for the last element which stays the same. Be careful not to index beyond the last element. Ex: Initial Scores: 10, 20, 30, 40 Scores after loop: 30, 50, 70, 40 Import. java.util.Scanner; public class StudentScores { public static void main (String [] args){ Scanner scnr = new Scanner (System.in); final int SCORES_SIZE = 4; int [] bonusScores = new int[SCORES_SIZE]; int...
Array testGrades contains NUM_VALS test scores. Write a for loop that sets sumExtra to the total...
Array testGrades contains NUM_VALS test scores. Write a for loop that sets sumExtra to the total extra credit received. Full credit is 100, so anything over 100 is extra credit. Ex: If testGrades = {101, 83, 107, 90}, then sumExtra = 8, because 1 + 0 + 7 + 0 is 8. Java COde: import java.util.Scanner; public class SumOfExcess { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); final int NUM_VALS = 4; int[] testGrades...
Write a for loop that prints: 1 2 ... userNum Ex: userNum = 4 prints: 1...
Write a for loop that prints: 1 2 ... userNum Ex: userNum = 4 prints: 1 2 3 4 import java.util.Scanner; public class ForLoops { public static void main (String [] args) { int userNum; int i; Scanner input = new Scanner(System.in); userNum = input.nextInt(); for (/* Your code goes here */) { System.out.print(i + " "); } } } Need to fill out the "for" solved in JAVA
Complete the program below. The program takes in two positive integers, n and m, and should...
Complete the program below. The program takes in two positive integers, n and m, and should print out all the powers of n that are less than or equal to m, on seperate lines. Assume both n and m are positive with n less than or equal to m. For example, if the input values are n = 2 and m = 40 the output should be: 2 4 8 16 32 Starter code: import java.util.Scanner; public class Powers {...
IN JAVA Methods*: Calorie estimator Write a method ActivityCalories that takes a string indicating an activity...
IN JAVA Methods*: Calorie estimator Write a method ActivityCalories that takes a string indicating an activity (sit, walk, jog, bike, swim) and duration in minutes (integer), and returns the estimated calories expended (double). Calories per minute for a 150 lb person (source): sit: 1.4 walk: 5.4 run: 13.0 bike: 6.8 swim: 8.7 If the input is sit 2, the output is 2.8 Hints: Use an if-else statement to determine the calories per minute for the given activity. Return the calories...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT