Avatar of chris0044
chris0044
 asked on

Min Value and Print User input

Hi,

I' m student and I'm having trouble printing out the minimum value and also to print out what the user inputs. Could someone tell me what I'm doing wrong?

public static void main(String args[]){
		
	int numbers;
	int inputData = 0;
	int largest = 0;
	int smallest = inputData;
	Scanner scan = new Scanner(System.in);
	
		System.out.print("How many numbers do you want to enter?");
		numbers = scan.nextInt();
		
		for (int index = 1; index <= numbers; index ++){
		System.out.print("Number " + index + ": ");
		inputData = scan.nextInt();
		if (inputData > largest){
			largest = inputData;
			if (inputData < smallest){
				smallest =inputData;
			}
		  }
		}
		
		System.out.println ("largest Value is " + largest);
		System.out.println ("smallest Value is " + smallest);
		
		System.out.println("You've entered: ");
		for (int index = 1; index <= numbers; index ++){
			System.out.print(inputData + " ");
		}
		
} 
} 

Open in new window

Java

Avatar of undefined
Last Comment
chris0044

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
dpearson

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.
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
chris0044

ASKER
I havechanged the if statements but the smallest values still doesn't give me the right answer. I have also changed int smallest = inputData; to int smallest = 0; but it doesn't work.
SOLUTION
dpearson

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.
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
chris0044

ASKER
Thanks, it works now
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