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

Write a java application that finds the smallest of several integers. Prompt the

ID: 3859493 • Letter: W

Question


Write a java application that finds the smallest of several integers. Prompt the user for the number of integers that will be input, then prompt the user for that number of integers. Evaluate the integers to determine the smallest value.

Run the program to test for 3 numbers
-- 50, 10, 100

Run the program a second time to test for 5 input number;
-- 7, -2, 0, 15, 5

Submit your .java, .class and results. The results may be copied and pasted at the bottom of the .java file OR placed in a word document.

Explanation / Answer

SmallestNo.java

import java.util.Scanner;

public class SmallestNo {

   public static void main(String[] args) {
       //Declaring variables
       int nos,min;
      
       //Scanner object is used to get the inputs entered by the user
               Scanner sc=new Scanner(System.in);
              
               //getting how many integers user want to enter
               System.out.print("Enter the number of integers :");
               nos=sc.nextInt();
              
               //creating an array based on the number entered by the user
               int[] arr=new int[nos];
              
               /* this for loop will get the numbers entered
               * by the user and populate those values into an array
               */
               for(int i=0;i<nos;i++)
               {
                   //Getting the number entered by the user
               System.out.print("Enter number"+(i+1)+":");  
               arr[i]=sc.nextInt();  
               }
              
               min=arr[0];
              
               //this for loop will find the minimum value of an array
               for(int i=0;i<nos;i++)
               {
                   if(min>arr[i])
                   {
                       min=arr[i];
                   }
               }

               //Displaying the minimum value of an array
               System.out.println("The Smallest number is :"+min);
   }

}

_______________

Output:

Enter the number of integers :3
Enter number1:50
Enter number2:10
Enter number3:100
The Smallest number is :10

_____________

Output#2:

Enter the number of integers :5
Enter number1:7
Enter number2:-2
Enter number3:0
Enter number4:15
Enter number5:5
The Smallest number is :-2

___________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote