Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***AgeInsult We now turn to the use of conditional statements to select from different code blocks depending on the value of a variable. This program

***AgeInsult

We now turn to the use of conditional statements to select from different code blocks depending on the value of a variable.

This program has a few bugs in it. It also uses a Scanner object to read data from the keyboard, making it more interactive than the programs we've written so far.

Here's what your program output should look like for several runs with different input values for age:

How old are you?

2

Too young to know any better.

How old are you?

5

Not ready for prime time.

How old are you?

13

Grow up.

How old are you?

25

Get a job!

How old are you?

125

Get a job!

Way too old!You are probably lying.

can i get help in this java program code?

/**CORRECT THE ERRORS! Find all 8 (or more?), if you dare!

*

* A program that reads an age that is typed in by the

* user and insults them

*/

import java.util.*;

public class AgeInsult {

public static void main(String args) {

Scanner keyboard = new Scanner(System.in);// creates a link to the keyboard

System.out.println("How old are you?");

int age = keyboard.nextDouble();// reads a double value from user

//Exactly one of these 4 main blocks will be executed.

if (age <= 3) {

System.out.println("Too young to know any better.")

else if (age < 10) {

Sytem.out.println(Not ready for prime time.);

}

else if (age < 18) {

System.out.println("Grow up.");

}

else (age >=18) {

System.out.println("Get a job!");

}

//if statement without "else if" or even an "else".

//this will either execute or not execute depending on age

if (age > 120) {

System.out.println("Way too old!You are probably lying.");

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions