Avatar of jtiernan2008
jtiernan2008 asked on

Can someone please help me with this simple java program

The question is to enter 3 numbers and find which is the larger of them but it will not run
Can someone please take a look at it.
import java.util.Scanner;
 
public class Largest {
	
	public static void main (String args[]) {
		
		Scanner input = new Scanner();
		
		int number1, number2, number3, weight1 = 0, weight2 = 0, weight3 = 0;
		
		System.out.println("Please enter the first number");
		number1 = input.nextInt();
		System.out.println("Please enter the second number");
		number2 = input.nextInt();
		System.out.println("Please enter the third number");
		number3 = input.nextInt();
		
		if ((number1 > number2) || (number 1 > number3)) {
			System.out.println("number 1 is the largest number");
		}
		
		if ((number2 > number1) || (number2 > number3)) {
			System.out.println("number 2 is the largest number");
		}
		
		if ((number3 > number 1) || (number3 > number1)) {
			System.out.println("number 3 is the largest number")
		}
		
		
		
	}
}

Open in new window

Java

Avatar of undefined
Last Comment
vahana

8/22/2022 - Mon
SOLUTION
Mick Barry

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Mick Barry

just a few typos really, and you neeed to pass System.in to the Scanner ctor

ASKER CERTIFIED SOLUTION
ksivananth

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
jtiernan2008

@ mahome

so why cannot I not use || which is 'or'?

Would it not mean one or the other or am I not understanding the context?
vahana

or try this one
import java.util.*;
 
public class Largest {
 
    public static void main(String args[]) {
 
        Scanner input = new Scanner(System.in);
        int maxNumber, number1, number2, number3,
                weight1 = 0, weight2 = 0, weight3 = 0;
        String MaxNumberName = "";
        System.out.println("Please enter the first number");
        number1 = input.nextInt();
        System.out.println("Please enter the second number");
        number2 = input.nextInt();
        System.out.println("Please enter the third number");
        number3 = input.nextInt();
 
        if (number1 > number2) {
            maxNumber = number1;
            MaxNumberName = "number1";
        } else {
            maxNumber = number2;
            MaxNumberName = "number2";
        }
        if (maxNumber < number3) {
            maxNumber = number3;
            MaxNumberName = "number3";
        }
        System.out.println(MaxNumberName + " is the largest number");
 
    }
}

Open in new window

I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
vahana

U are right but if u want find largest number ur condition is not correct