Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#72012 5-11) (Find the Smallest Value ) Write an application that finds the smal

ID: 3815712 • Letter: #

Question

#72012

5-11) (Find the Smallest Value ) Write an application that finds the smallest of several integers . Write a program which first asks the user to enter the number of values to enter, then asks for each value , and finally prints out the lowest value of those entered.

SAMPLE RUN #4: java SmallestValue:

Enter·the·number·of·integers·you·are·going·to·enter:6
Enter·the·1·of·6·number:789
Enter·the·2·of·6·number:123
Enter·the·3·of·6·number:456
Enter·the·4·of·6·number:369
Enter·the·5·of·6·number:258
Enter·the·6·of·6·number:723
The·lowest·number·is·123

Explanation / Answer

SmallestValue.java

import java.util.Scanner;

public class SmallestValue {

   public static void main(String[] args) {
       //Declaring variables
       int size,min;
       //Scanner object is used to get the inputs entered by the user
               Scanner sc=new Scanner(System.in);
              
               //Getting the size of an array
               System.out.print("Enter·the·number·of·integers·you·are·going·to·enter:");
               size=sc.nextInt();
              
               //creating an array based on the user entered size
               int nos[]=new int[size];
              
               /* getting the numbers entered by the user and
               * populating those values it an array
               */
               for(int i=0;i<size;i++)
               {
                   //Getting the input entered by the user
                   System.out.print("Enter·the·"+(i+1)+"·of·"+size+"·number:");
                   nos[i]=sc.nextInt();
               }

               min=nos[0];
              
               //this for loop will find the minimum of all user entered numbers
               for(int i=0;i<size;i++)
               {
                   if(min>nos[i])
                       min=nos[i];
               }
              
               //Displaying the Minimum number
               System.out.println("The·lowest·number·is·"+min);
              
   }

}

__________________

Output:

Enter·the·number·of·integers·you·are·going·to·enter:6
Enter·the·1·of·6·number:789
Enter·the·2·of·6·number:123
Enter·the·3·of·6·number:456
Enter·the·4·of·6·number:369
Enter·the·5·of·6·number:258
Enter·the·6·of·6·number:723
The·lowest·number·is·123

___________Thank You