Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6810141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:10:13+00:00 2026-05-26T20:10:13+00:00

I am a little stuck with my coursework in JAVA. Could you help me?

  • 0

I am a little stuck with my coursework in JAVA. Could you help me?

let’s say you want to write a program that repetitively asks the names of people and their age and stops when the string FINISH is entered, then prints out the name and the age of the youngest person of all the people entered. And if 2 or more people have the same age, jsut write the name of the last person of that age entered. How can you ask JAVA to select that person, without the use of arrays, but only while loops, if statements and for loops.

Here is the example, starting from the method.

String name = "";

int age = 0;

while (!name.equals ("finish))    

{ 
   name = JOptionPane.showInputDialog ("Give name: ");

   String ageText = JOptionPane.showInputDialog ("Give age: ");

   int age = Integer.parseInt (ageText);    
}

JOptionPane.showMessageDialog ("the yougest person is " + age + ". It's " + name + ".");

An example run of the program:

Give name: Lucy
Give age: 52

Give name: Paul
Give age: 29

Give name:John
Give age: 28

Give name: Mary
Give age: 31

Give name: finish

The youngest person is 28. It’s John.

Please note how string “finish” is not printed out at the end.

I have been thinking trying to find a way of doing that for 8 hours. I beg you help please.

Kind regards,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:10:14+00:00Added an answer on May 26, 2026 at 8:10 pm

    You need to add more variables to keep track of what is currently known to be the youngest age and the person associated with it:

    String name="", youngName;
    int age=Integer.MAX_VALUE, youngAge;
    
    while (!name.equals("FINISH")) {
        name = JOptionPane.showInputDialog("Enter a name: ");
        age = Integer.parseInt(JOptionPane.showInputDialog("Enter " + name + "'s age: "));
    
        if(age <= youngAge && !name.equals("FINISH")) {
            youngAge = age;
            youngName = name;
        }
    }
    
    JOptionPane.showMessageDialog("The youngest age is: " + youngAge + ".  It's " + youngName + ".");
    

    Be careful that the program will break if you input something that isn’t a number into the age field, and does not account for the fact that there might be two or more people with the lowest age.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm working on a Black jack program and I'm a little stuck. I'll
Im a little stuck and I dont know what im doing wrong. I want
I need a regular expression find and replace that I'm a little stuck on.
I'm getting a little stuck with two entwined problems. First, I want to have
A little stuck here. I have a simple question I guess. Given the following
I got a little stuck and I'm hoping someone can point me in the
I'm a little stuck, it's due to my inexperience with html/css and iframes. Basically,
I am pretty new to the Unity Application Block and am a little stuck
I'm making a script parser in python and I'm a little stuck. I am
I apologize for the subjectiveness of this question, but I am a little stuck

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.