ask a user to enter 5 integer

ask a user to enter 5 integer

make a program that enter 5 numbers then identify the largest and the smallest number

sample program 2 4 3 5 6 the smallest number: 2 the largest number: is 6

66

View Answers

November 8, 2012 at 1:31 PM

Here is a code that accepts five numbers and find the largest and smallest number from the array of input numbers.

import java.util.*;

public class FindLargestSmallestNumber {

        public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        System.out.println("Enter 5 numbers: ");
        int numbers[] = new int[5];
        for(int i=0;i<numbers.length;i++){
            numbers[i]=input.nextInt();
        }
        int smallest = numbers[0];
        int largest = numbers[0];

        for(int i=1; i< numbers.length; i++)
        {
        if(numbers[i] > largest)
        largest = numbers[i];
        else if (numbers[i] < smallest)
        smallest = numbers[i];

        }

        System.out.println("Largest Number is : " + largest);
        System.out.println("Smallest Number is : " + smallest);
        }
        }

Ads









Related Tutorials/Questions & Answers:
ask a user to enter 5 integer
ask a user to enter 5 integer  make a program that enter 5 numbers then identify the largest and the smallest number sample program 2 4 3 5 6 the smallest number: 2 the largest number: is 6 66
accept integer from user
accept integer from user  Write an Java application that accepts 100 integer numbers from a user. The input should be in the range of 1-200. Error message needs to be displayed if user entered input which is not in this range
Advertisements
Integer exception in java
the character input stream. The program will ask the user to enter the number , if the user enter the number other than integer it will gives an exception error. if the user enters integer it will display the number which the user have
ask user how many numbers to be inputted and determine the sum and highest number using an array in java
ask user how many numbers to be inputted and determine the sum and highest number using an array in java  ask user how many numbers to be inputted and determine the sum and highest number using an array in java
I have a tex box. in that i want user should enter data in the format specified(for eg--a_b_c_d_e_)how to write code for it.
I have a tex box. in that i want user should enter data in the format specified(for eg--a_b_c_d_e_)how to write code for it.  I have a tex box. in that i want user should enter data in the format specified(for eg--abcde_)how
Change the user input to integer
Change the user input to integer   ... an integer value after the compilation of a program and force the JVM to ask... to enter a integer in a method or class using keyboard, then we have to use
Allow to Enter only numeric data.
Allow to Enter only numeric data.  hi....... I want to ask that in my project i have a textfield where user is going to enter the data so i want that the user should allow to enter only numeric data. I mean to say that if user
Java Reverse integer array
order. In the main method, we have allowed the user to enter numbers...]); } } } Output: Enter five array elements: 3 5 6 2 4 Array In Reverse Order: 4...Java Reverse integer array In this tutorial, you will learn how to reverse
Servlet Error Message based on user input
; which renders an input field to enter the name of the user. Here is the code...Servlet Error Message based on user input       In this example user is presented with a screen
Java coding for beginners
: This is just an example... Inputting and Echoing integer and string entered by user If the program prompt input from user their will be declaration of variables...; //num1 is a variable of integer type you can change it String word1; //string
Ask date difference
Ask date difference  Hello, I have a problem about how to calculate... || curmonth == 5 || curmonth == 7 || curmonth == 8 || curmonth == 10 || cur_month... dates from the user and calculates the date difference in terms of days. import
Convert a String into an Integer Data
program we have prompted the user to enter the a String and then reads the data... Enter an integer number: 10 String: 10 Integer: 10... Convert a String into an Integer Data  
integer to string
integer to string  i have to develop a program which convert integer into character from 1 to 10,000 if we input 1 then it give output 'one' n so on till 'ten thousand' kindly give me the codes plzplz sir........   Have
Initializing Integer Variable issue?
Initializing Integer Variable issue?  My program is supposed to take... problem is my integer variables (number0 - number6). It is forcing me to initialize...; inputPhrase = JOptionPane.showInputDialog("Enter your phrase
How to handle enter key in javascript
How to handle enter key in javascript  Can any one tell me how to handle the enter key event on a Button in HTML. Like in my simple HTML page i want to submit the form even if user hits the enter key from keyboard instead
Program to Ignore Space and Enter ?!
Program to Ignore Space and Enter ?!  Hi, dear friend i wont to write program to enter many statements, if i use Space and Enter in the Run Time must be delete the space and ignore the Enter ..for example if i entered
Ask about looping in database
Ask about looping in database  Good afternoon, I want to ask... = False | 1/2 | | 5 | A3 | If A1...=True,A2=True : code is the same data Rule and Heritage. I want to ask
Convert Hexadecimal number into Integer
to convert hexadecimal data into integer. The java.lang package provides the functionally to convert the hexadecimal data into an integer type data.  Code Description: The following program takes an integer type data at the console
ModuleNotFoundError: No module named 'ask'
ModuleNotFoundError: No module named 'ask'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ask' How to remove the ModuleNotFoundError: No module named 'ask' error
Convert Decimal to Integer
Convert Decimal to Integer      ... into an integer. The java.lang package provides the functionality to convert a decimal number to an integer type number. Description Code: This program helps you
Ask java count
Ask java count  Good morning, I have a case where there are tables sumborrowbook fieldnya: codebook, bookname, and sumborrowbook . I want to make... | Java 1 | 10 | | b002 | beginner java | 5
Convert Integer to Double
IntegerToDouble Enter the integer value: 24 Double:=24.0... Convert Integer to Double        In this section, you will learn to convert an integer
ModuleNotFoundError: No module named 'integer'
ModuleNotFoundError: No module named 'integer'  Hi, My Python... 'integer' How to remove the ModuleNotFoundError: No module named 'integer... to install padas library. You can install integer python with following command
Create an array of 5 doubles...
Create an array of 5 doubles...  Part one In a Java program, create an array of 5 doubles. Have the user input values into these array items inside a loop using JOptionPane. Using the loop, calculate the sum and average of the 5
Convert Euro to dollar, need to be able to enter decimal!
Convert Euro to dollar, need to be able to enter decimal!  Hi... currency conversion from euros to dollars: it prompts the user for the conversion... the number of dollars). The program then repeatedly asks the user for a quantity
Convert Euro to dollar, need to be able to enter decimal!
Convert Euro to dollar, need to be able to enter decimal!  Hi... currency conversion from euros to dollars: it prompts the user for the conversion... the number of dollars). The program then repeatedly asks the user for a quantity
Convert an Integer into a String
. C:\corejava>java IntegerToString Enter the integer value... Convert an Integer into a String       In this section, you will learn to convert an integer
ModuleNotFoundError: No module named 'enter-leave'
ModuleNotFoundError: No module named 'enter-leave'  Hi, My Python... 'enter-leave' How to remove the ModuleNotFoundError: No module named 'enter-leave' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'enter-leave'
ModuleNotFoundError: No module named 'enter-leave'  Hi, My Python... 'enter-leave' How to remove the ModuleNotFoundError: No module named 'enter-leave' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'wechat_enter'
ModuleNotFoundError: No module named 'wechat_enter'  Hi, My Python... 'wechat_enter' How to remove the ModuleNotFoundError: No module named 'wechat_enter' error? Thanks   Hi, In your python
swap two integer arrays
swap two integer arrays  int [] array1 = {1,2,3,4,5} int [] array2 = {6,7,8,9,10} how can we swap the values of bith integer arrays results like this array1 = {6,7,8,9,10} array2 = {1,2,3,4,5

Ads