Question

In: Computer Science

Write a Java program to do the following USING ARRAYS 1) input 15 integers (input validation,...

Write a Java program to do the following USING ARRAYS

1) input 15 integers (input validation, all numbers must be between 0 and 100)

2) find the largest number.

3) Find the Smallest Number

4) Find the Sum of all numbers in the Array

Display:

Largest Number

Smallest Number

Sum of all numbers

the original Array

DO NOT USE METHODS OR FUNCTIONS

Solutions

Expert Solution

import java.util.*;

public class Main
{
   public static void main(String[] args) {
       Scanner s = new Scanner(System.in);
       int a[] = new int[15];
       int flag = 0, sum = 0, max = -1, min = 101;
       while(true)
       {
       sum = 0;
       max = -1;
       min = 101;
       System.out.print("Enter the 15 elements : ");
       for(int i = 0; i < 15; i++)
       {
       int n = s.nextInt(); // read the elemetns
       if(n > 0 && n < 100)
       {
       a[i] = n;
       sum = sum + n; // summation of numbers
       if(n < min)
       {
       min = n; // find minimum
       }
       if(n > max)
       {
       max = n; // find maximum
       }
       }
       else{
       System.out.println("Number should be between 0 and 100");
       flag = 1;
       }
       }
       if(flag == 1)
       {
       flag = 0;
       continue;
       }
       else{
       break;
       }
   }
  
   System.out.println("Enter the largest number : " + max); // print the largest number
   System.out.println("Enter the smallest number : " + min); // print the smallest number
   System.out.println("Sum of all numbers : " + sum); // print the summation of number
   System.out.print("Print the original array : "); // print the original array
   for(int i = 0; i < 15; i++)
   {
   System.out.print(a[i] + " ");
   }
   }
}
OUTPUT :


Related Solutions

Write a C++ program to do the following USING ARRAYS 1) input 15 integers (input validation...
Write a C++ program to do the following USING ARRAYS 1) input 15 integers (input validation , all numbers must be between 0 and 100) 2) find the largest number 3) Find the Smallest Number 4) Find the Sum of all numbers in the Array Display: as per the user's section (menu using switch or if else ) Largest Number Smallest Number Sum of all numbers the original Array DO NOT USE METHODS OR FUNCTIONS Submit: Source code (C++) output...
Write a JAVA program by making a LOGIN form using Excel file for validation. if user...
Write a JAVA program by making a LOGIN form using Excel file for validation. if user is found, display the user's First Name and Last Name.
Write a program in Java to do the following: -Create a one-dimensional array of 7 integers...
Write a program in Java to do the following: -Create a one-dimensional array of 7 integers as follows: Assign {35,20,-43,-10,6,7,13} -Create a one dimensional array of 7 Boolean values as follows: Assign {true,false,false,true,false,true,false} -Create a one dimensional array of 7 floating-point values as follows: Assign {12.0f,1.5f,-3.5f,-2.54f,3.4f,45.34f,22.13f} -Declare sum as integer and set it to 0. -Declare sumf as float and set it to 0.0f. -Use a for loop to go through each element of the Boolean array, and if an...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code. Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input...
Write program#1 upload .java file. #1 Write a java program that prompts the user for input using the Scanner class. First to enter their first name. Then prompts the user to enter their last name. Then prompts the user to enter their city. Then prompts the user to enter their state. Then prompts the user to enter their zip code.   Concatenate first name and last name into full_name. Using String Class is optional. Use the String Class to replace zip...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of...
Using a Java. 2. Write a Java program calculate_fare.java to take the input for number of miles, and the class of journey (1,2, or 3, for first, second, and third class respectively), for a train journey. The program should then calculate and display the fare of journey based on the following criteria: Note: Use Switch...case and if...else construct First (1) Class Second (1) Class Third (3) Class First 100 mile $ 3 per mile $ 2 per mile $ 1.50...
In Java, what is the advantage of using ArrayList over arrays? Write a program to perform...
In Java, what is the advantage of using ArrayList over arrays? Write a program to perform following operations a. Create a class named Rectangle with two properties “height” and “width”. Create a parameterized constructor to initialize “height” and “width” values. b. Write method area() to calculate and return area of Rectangle. c. Create an ArrayList to store Rectangle objects. d. Create three Rectangle objects of width and height set to (2, 3), (3, 3) and (4, 5) and add them...
Write an error-free Java program to do the following things. Prompt the user to input a...
Write an error-free Java program to do the following things. Prompt the user to input a set of numbers. The numbers represent hourly wages so they will be between 7.25 (peon) and 50 (big boss). The user should be able to input up to 35 numbers but if the user enters 0 then the data input ceases. All of the data that the user enters should be stored in a single array. You do not need to check the input...
how to create BANKACCOUNT program using Arrays in JAVA.
how to create BANKACCOUNT program using Arrays in JAVA.
Using Dev-C++ write a program that allows a small business owner to input, in parallel arrays,...
Using Dev-C++ write a program that allows a small business owner to input, in parallel arrays, the type of item, its cost, and the number in stock. The program should output this information in the form of a table. The output will look something like below. Also, assume for a finite number of item name of 3 Item Name Cost Number in Stock Widget 25.00 4 ... ... ... Wombet 47.50 9 Prelude to Programming (6th edition)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT