Question: Using a object to read input requires that data type entered must match the data type expected by the program ( and vice versa )

Using a object to read input requires that data type entered must match the data type expected by the program (and vice versa). Run the program provided in the template below. Enter data as follows:What is your age? 18
What is your income? 15004.46
What is your name? YourNameHere
import java.util.Scanner; // Needed for the Scanner class
/*
This program has a problem reading input.
*/
public class InputProblem
{
public static void main(String[] args)
{
String name; // To hold the user's name
int age; // To hold the user's age
double income; // To hold the user's income
// Create a Scanner object to read input.
Scanner keyboard = new Scanner(System.in);
// Get the user's age.
System.out.print("What is your age? ");
age = keyboard.nextInt();
// Get the user's income
System.out.print("What is your annual income? ");
income = keyboard.nextInt();
// Get the user's name.
System.out.print("What is your name? ");
keyboard.nextLine();
name = keyboard.nextLine();
// Display the information back to the user.
System.out.println("Hello,"+ name +". Your age is "+
age +" and your income is $"+
income);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!