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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started