Link to home
Start Free TrialLog in
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

ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chris0044
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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, it works now