Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



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

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


gemini2
ask a user to enter 5 integer
1 Answer(s)      a year and 11 months 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


Advertisement
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 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
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
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
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
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 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
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
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
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
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 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
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
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
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
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
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
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
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
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
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
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
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
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 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  
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
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
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... is the example code: String s =request.getParameter("myvariable"); Integer i
 

 

 

DMCA.com