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 6864947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:58:41+00:00 2026-05-27T02:58:41+00:00

This is a program that is supposed to prompt the user to enter three

  • 0

This is a program that is supposed to prompt the user to enter three numbers and
then display the largest of these numbers. However, there are logic errors in it. I’m stuck on trying to figure out where this little bugger is. Please use your expertise to lend me a hand. I am a student, so please don’t rage on me \:p

import java.util.*;
public class HA8LargestErr {
    private int num1;
    private int num2;
    private int num3;

    public HA8LargestErr() {
        num1 = 0;
        num2 = 0;
        num3 = 0;
    }

    public void  getNumsFromUser() {
        Scanner input = new Scanner (System.in);
        System.out.println("Enter three numbers: ");
        num1 = input.nextInt();
        num2 = input.nextInt();
        num3 = input.nextInt();
    }

    public int returnLargest() {
        if (num1 > num2 && num1 > num3)
            return num1;
        if (num2 > num3 && num2 > num1)
            return num2;
        return num3;
    }


    public static void main(String[] args) {
        HA8LargestErr data = new HA8LargestErr();

        data.getNumsFromUser();
        System.out.println ("The largest is : " + data.returnLargest());
    }
}
  • 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-27T02:58:42+00:00Added an answer on May 27, 2026 at 2:58 am

    Replace your implementation of returnLargest with

    public int returnLargest() {
        if (num1 >= num2 && num1 >= num3)
            return num1;
        if (num2 >= num3)
            return num2;
        return num3;
    }
    

    Or use Math.max as suggested above.

    Edit:

    You need to use >= instead of > because otherwise num3 will be returned when num1 and num2 are equal and larger than num3.

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

Sidebar

Related Questions

This is a program that is supposed to prompt user for hours worked and
I bought this program that created a pretty nice imageuploader flash script however I
There's this program, pdftotext, that can convert a pdf file to a text file.
I have spent many hours working on this program that is supposed to play
This program simply is supposed to eliminate duplicates from an array. However, the second
I am supposed to write a program that should read from input numbers in
This program is supposed to take in a three digit number and change it
Suppose that I have a Java program within an IDE (Eclipse in this case).
So I have this program that I really like, and it doesn't support Applescript.
I have this program that should execute a piece of code base on the

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.