Posts

Showing posts with the label terminated by 0

Input a list of positive numbers, terminated by 0, into an array Numbers[]. Then display the array and the largest and smallest number in it.

 Input a list of positive numbers, terminated by 0, into an array Numbers[]. Then display the array and the largest and smallest number in it. The solution is designed in a simpler way.  import java.util.Arrays; import java.util.Scanner; public class ReadingWithScanner {    public static void main(String args[]) {       Scanner s = new Scanner(System.in);       int [] myArray = new int[5];       int smallest = myArray[0];       int largest = myArray[0];       System.out.println("Enter the elements of the array:");       for(int i=0; i<myArray.length; i++ )       {               int l =s.nextInt();          if (l != 0)          {             myArray[i] = l;          }          else{   ...