QuestionAsk Questions?

an application that finds the smallest of several integers. assume the first value read specifies the number of values to input from the user. please help!!!

View Answers

September 29, 2011 at 3:46 PM

import java.util.*; class NumberApplication{ public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("How many numbers you want to enter: "); int num=input.nextInt(); int numbers[] = new int[num]; for(int i=0; i < numbers.length; i++){ numbers[i]=input.nextInt(); } int smallest = numbers[0]; for(int i=1;i<numbers.length;i++){ if(numbers[i] < smallest){ smallest = numbers[i]; } } System.out.print("Smallest Number: "+ smallest); } }

Related Tutorials/Questions & Answers: