Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Practical Issues In Database Management A Refernce For The Thinking Practitioner

Authors: Fabian Pascal

1st Edition

0201485559, 978-0201485554

More Books

Students also viewed these Databases questions

Question

What is the formula to calculate the mth Fibonacci number?

Answered: 1 week ago

Question

1. Which position would you take?

Answered: 1 week ago