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);
        }
        }









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
find largest num enter by user using loop method - Java Interview Questions
find largest num enter by user using loop method  hi..it's me again.. thanks for answering my question.. i wanna ask, if i wanna use loop... like this: for(int i=1; i<=5; i++){ System.out.println("Enter value
find the largest number enter by user - Java Interview Questions
find the largest number enter by user  sorry for not stating clearly my question. i want to know how to find the largest number enter by user...(fwriter); for(int i=1; i<=5; i++) { System.out.print("Enter a number
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
Integer exception in java
to read text from 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... in it. In case the user enter a value other than integer, exception will caught
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
Servlet Error Message based on user input
;test.jsp" which renders an input field to enter the name of the user...Servlet Error Message based on user input       In this example user is presented with a screen
Ask Questions with Options
Ask Questions with Options using Java In this section, we are going to ask five questions one after the other with four options to test the user. For this, we have stored 5 questions, answers with four options into a list. The list
Java Reverse integer array
order. In the main method, we have allowed the user to enter numbers...]); } } } Output:ADS_TO_REPLACE_1 Enter five array elements: 3 5 6 2 4 Array...Java Reverse integer array In this tutorial, you will learn how to reverse
The largest integer among the X number
will then ask the user if he/she wishes to exit the program or repeat the entire...The largest integer among the X number  Write an application program that prompts the user to key in a whole number X. The user is then prompted
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
Java coding for beginners
;); } } Output: 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... your own too. int num1; //num1 is a variable of integer type you can change
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
Convert a String into an Integer Data
;} } In the above program we have prompted the user to enter... C:\vinod\convert>java StringToInt Enter an integer number... Convert a String into an Integer Data  
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
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
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
it can be submitted by hitting ENTER
it can be submitted by hitting ENTER  How do I make a form so it can be submitted by hitting ENTER
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
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
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 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:ADS_TO_REPLACE_1
Ask for latest version for hibernate
Ask for latest version for hibernate  any new version for hibernate after 3.0, if yes can u give some exmp for latest version of hibernate
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
Ask about java
Ask about java  Create a java program for add and remove the details of a person, which is not using by database, a simply java program. If possible, please wil it in switch case
Convert Integer to Double
. C:\corejava>java IntegerToDouble Enter the integer value... Convert Integer to Double        In this section, you will learn to convert an integer
Convert Hexadecimal number into Integer
HexaToInteger Enter the hexadecimal value:! 24 Integer:=36... to convert hexadecimal data into integer. The java.lang package provides the functionally to convert the hexadecimal data into an integer type data.  Code
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
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
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
Convert an Integer into a String
Enter the integer value! 24 string: 24 C:\corejava>... Convert an Integer into a String       In this section, you will learn to convert an integer
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 Character into Integer
Convert Character into Integer   ... into a integer. The java.lang package convert provides the facility to convert the character data into an integer type. Description of code:ADS_TO_REPLACE_1
ask java - Date Calendar
ask java  sory i'am wrong language. i want to ask to this forum how to take calender to another frame. now we can find like "datapicker" in VB but in java i found too but i can't to join in another frame. And i want to ask how
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
get integer at run time
get integer at run time  how to get integer value at run time in j2ee using servlets   Hi, You can get the value from request parameter... Here is the example code: String s =request.getParameter("myvariable"); Integer
ask - Java Beginners
ask   dear how to "print out" into a file ? regard suhadi  Hi friend, Please explain properly requirement. I am sending simple code according to your requirement. import java.io.*; public class
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 Integer to Float
;java IntegerToFloat Enter a integer value! 24 Float:=24.0... Convert Integer to Float       In this section, you will learn to convert an integer type data
ModuleNotFoundError: No module named 'ask-schools'
ModuleNotFoundError: No module named 'ask-schools'  Hi, My Python... 'ask-schools' How to remove the ModuleNotFoundError: No module named 'ask-schools' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'ask-schools'
ModuleNotFoundError: No module named 'ask-schools'  Hi, My Python... 'ask-schools' How to remove the ModuleNotFoundError: No module named 'ask-schools' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'ask-sdk'
ModuleNotFoundError: No module named 'ask-sdk'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ask-sdk' How to remove the ModuleNotFoundError: No module named 'ask-sdk
ModuleNotFoundError: No module named 'ask-sdk'
ModuleNotFoundError: No module named 'ask-sdk'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ask-sdk' How to remove the ModuleNotFoundError: No module named 'ask-sdk
ModuleNotFoundError: No module named 'falcon-ask'
ModuleNotFoundError: No module named 'falcon-ask'  Hi, My Python... 'falcon-ask' How to remove the ModuleNotFoundError: No module named 'falcon-ask' error? Thanks   Hi, In your python environment you

Ads