Home Answers Viewqa Java-Beginners ask a user to enter 5 integer

 
 


gemini2
ask a user to enter 5 integer
1 Answer(s)      6 months and 13 days ago
Posted in : Java Beginners

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 Pages:
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
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
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
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
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
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
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
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
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
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 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
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
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
Need help on mySQL 5 - SQL
Need help on mySQL 5  Dear Sir, I'm a beginner of mySQL 5 . I need... to enter into the MS DOS using aggregate function MAX to display the output as shown.... Regards, Christopher de Souza   dear user you have to use a nested sql
SWT "Enter" key event - Swing AWT
SWT "Enter" key event  Can any one post me the sample code to get the enter key event? My requirement is , I want some SWT button action to be done when the user presses "Enter" key. Thanks in advance.  Hi friend
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
Java Programming: Chapter 5 Exercises
Programming Exercises For Chapter 5 THIS PAGE CONTAINS programming exercises based on material from Chapter 5 of this on-line Java textbook... the data are added one after the other calling the enter() method over and over
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
want to ask how to update data for runtime selected multiple checkboxes
want to ask how to update data for runtime selected multiple checkboxes ...); //alert("enter"); if(f1.elements[cnt].checked==true){ values[j]=f1.elements...;/th><tr>"); System.out.println("enter"); int i=1; while(rs.next
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
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
calculation after if. user input
; } if (fruit ==5){ System.out.print("Enter quantity of apples...calculation after if. user input  System.out.print ("please select...("5. Turnips"); System.out.println("6. Carrots"); fruit = in.nextInt
how to search for string using LIKE operator instead of integer?
how to search for string using LIKE operator instead of integer?  ...". what my code does is goes to the "index.jsp" file and let the user enters an ID..., itemname, and description. the itemid is in hyperlink so when the user click
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
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
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
Creating an Encyclopedia using Java & mySQL 5 - Java Beginners
is increased accordingly in the database. 2. You shall allow the user to enter...Creating an Encyclopedia using Java & mySQL 5  Dear Editor, I'm... are to allow the user to search for a word. If the word is not found, a message would
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: This program
Sitemap JEE 5 Tutorial Section
Home | About-us | Contact Us | Advertisement | Ask Questions | Site Map | Business Software Services India JEE 5 Tutorial Section JEE technologies | JEE 5 APIs | Sun Java System Application Server Platform Edition
What are the level in Jboss 5 application server to deploy the application
What are the level in Jboss 5 application server to deploy the application  What are the level in Jboss 5 application server to deploy... (such as integer). - Enumerations: the enum keyword creates a typesafe, ordered list
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
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
retreive integer data from database
retreive integer data from database  i made a table named result... as an integer(rollno) and the marks associated with that must be displayed.i write...=DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb" + "?user=root&password
Convert Integer to Float
Convert Integer to Float       In this section, you will learn to convert an integer type data into a float. The following programs helps you in converting an integer
Convert a String into an Integer Data
Convert a String into an Integer Data   ... type data into an integer type. The java.lang package provides the functionality to convert the string type data into an integer type data. Code Description
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
get details of employee after enter the emp_id
get details of employee after enter the emp_id  how to get employee details after entered the emp_id from database after that we have three more... links: http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/jsp
get details of employee after enter the emp_id
get details of employee after enter the emp_id  how to get employee details after entered the emp_id from database after that we have three more... links: http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/jsp
Java: Method Exercises 5
Java NotesMethod Exercises 5 Name: _________________________________ What... 2 3 4 5 6 7 8 9 10 11...)); int n = 5; output("C. ", inc(inc(inc(n)))); output("D. ", n
Ask PHP Questions
Ask PHP Questions       PHP Questions and Answers Ask PHP Questions and get answers from.... In your questions and answers section you can ask PHP questions and get
answer this qs in 5 mins plss
answer this qs in 5 mins plss  Create an Web Application, which allows a user to search a book as follows: Based on ISBN code, if he is aware... be displayed to the user. Please ensure MVC pattern is followed and all
enable users to enter names - Java Beginners
enable users to enter names  this is the code for tic tac toe game, i...[][] { {0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, {0, 4...[][] winCombinations = new int[][] { {0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6}, {1
Ask Java Questions Online
Ask Java Questions Online   ... Developer Company has just begun a new service ‘ask question online’ to resolve your query. Through using this service, you can ask
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
Java: Rainfall user interface - Console
Java NotesRainfall user interface - Console 1 2 3 4 5 6... - Condole user interface to RainfallStats // This separates the user interface...(String[] args) { //... Initializations String prompt = "Enter
how to check and print the no of times an integer is repeated in an array
how to check and print the no of times an integer is repeated in an array  how to check and print the no of times an integer is repeated in an array??? suppose my input is 2 4 2 5 2 4 3 4 5 2 then my output should be 2-4
java program (integer/decimal) - Java Beginners
java program (integer/decimal)  Accept a number from the user as command line arguments. The number could be an integer or decimal value. ? Display the absolute value of the input number ? Display the rounded off value
JEE 5 API
JEE 5 API       The list presented here will list the APIs available on the Java EE 5 platform... 5 The main focus of Java Platform, Enterprise Edition 5 (Java EE 5
Hibernate's Built-in criterion: Between (using Integer)
Hibernate's Built-in criterion: Between (using Integer... will learn to use "between" with the Integer class. "Between" when used with the Integer object, It takes three parameters e.g.  between("

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.