Question: I am trying to write a program in Java that asks for user input from two people. It will ask the user to input their

I am trying to write a program in Java that asks for user input from two people. It will ask the user to input their name and age. After that it will display the user who is older. But I am having issues. I will show what I have so far and what is happening when I run.

import java.util.Scanner;

class Main { public static void main(String[] args) {

Scanner sc = new Scanner(System.in); int age; String name; System.out.println("Enter the first name:"); name = sc.nextLine();

System.out.println("Enter the first persons age:"); age = sc.nextInt();

System.out.println("Enter the Second name:"); name = sc.nextLine();

System.out.println("Enter the second persons age:"); age = sc.nextInt(); } }

**It will ask for first users name then their age. But for the second user is asks for their name and age at the same time and doesnt allow the user to input anything.

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!