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



Home Answers Viewqa Java-Interview-Questions find the largest number enter by user
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


rayda
find the largest number enter by user
2 Answer(s)      5 years and 10 months ago
Posted in : Java Interview Questions



Advertisement
View Answers

January 30, 2009 at 10:52 PM


Hi rayda

I got it your query, i am sending solved code here you can implement it in your code easily...


import java.util.Scanner;

public class Input{
public static void main(String[] args) {
String name;
int age;
Scanner in = new Scanner(System.in);

System.out.println("Enter Name: ");
name = in.nextLine();

System.out.println("Enter Age: ");
age=in.nextInt();

in.close();

System.out.println("Name :"+name);
System.out.println("Age :"+age);
}
}

Thanks...


January 31, 2009 at 5:26 AM


Hi rayda
This is your code, which has solved...

import java.io.*;
import java.util.Scanner;

public class ReadNumber{
public static void main(String[]args) throws IOException{
int num,max,min;
String filename;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter the filename: ");
filename=keyboard.nextLine();
FileWriter fwriter=new FileWriter(filename);
PrintWriter outputFile=new PrintWriter(fwriter);

int a, b, c, d, e;
Scanner in = new Scanner(System.in);

System.out.println("Enter first value: ");
a=in.nextInt();
System.out.println("Enter second value: ");
b=in.nextInt();
System.out.println("Enter third value: ");
c=in.nextInt();
System.out.println("Enter four value: ");
d=in.nextInt();
System.out.println("Enter five value: ");
e=in.nextInt();

System.out.println(a +" || "+ b +" || "+ c +" || "+ d +" || "+ e);

int arr[] = {a, b, c, d, e};
max = arr[0];
min = arr[0];

for(int j=0; j<5; j++){
if(max < arr[j]){
max = arr[j];
}else if(min > arr[j]){
min = arr[j];
}
}
System.out.print("\nGreatest Number: "+ max);
System.out.print("\nSmallest Number: "+ min);

//in.close();

for(int i=1; i<=5; i++){
System.out.print("\nEnter a number: ");
num=keyboard.nextInt();
outputFile.println(num);
keyboard.nextLine();
}
outputFile.close();
int sum;
String str;
double average;
FileReader freader=new FileReader(filename);
BufferedReader inputFile=new BufferedReader(freader);
sum=0;
str=inputFile.readLine();

while(str!=null){
sum=sum+Integer.parseInt(str);
str=inputFile.readLine();
}
inputFile.close();
System.out.println("The sum is: "+sum);
average=sum / 5.0;
System.out.println("the average is: "+average);
}
}
Thanks...


Related Tutorials/Questions & Answers:
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...(); System.out.println("Enter five value: "); e=in.nextInt(); is it possible to find the largest number?.. thanks again..  Hi You can implement it in loop
Advertisements
Find Second Largest Number from an Array
Find Second Largest Number from an Array This section illustrates you how to find the second largest number from an array. For this purpose, we have allowed the user to enter the array elements of their choice and determine the largest
how to find largest number? - Java Interview Questions
want to find the greater number which user enter on the console? Thanks...how to find largest number?  this is my java coding: import...); } } i don't know how to add code to find the largest number.. please help
USE ARRAY TO FIND THE LARGEST NUMBER AND OCCURRENCE
USE ARRAY TO FIND THE LARGEST NUMBER AND OCCURRENCE  i have some... it is: write a program that reads 10 numbers from the keyboard. find the largest number and count the occurrence of the largest number number entered from the keyboard
find largest value
recently input by the user. c. largest: The largest number found so far.   Java Find Largest Number import java.util.*; class FindLargest...find largest value  (Assignment 1 - LargestValue)The process
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
The largest integer among the X number
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... information : a) The largest integer among the X number of integers keyed in b
Determining the largest number
Determining the largest number     ... the coding for determining the largest number amongst three. Here we have taken three...; conditions that can help you in finding the largest value one by one. 
Determine Average by removing Largest and Smallest Number
Determine Average by removing Largest and Smallest Number In this section, you will learn how to remove largest and smallest number from the 10 numbers.... These numbers are then stored into an array in order to find the largest
to read number from user
to read number from user  1)print the positive equivalent of the number 2) check if the no is integer or not 3) find the square root of the number 4) find the cube of the number
Find prime factors of non prime number
Find prime factors of non prime number In this section, you will learn how to find the prime factors of the non prime number. Here we have prompted the user to enter any number. If the number entered by the user is prime then we have
A program to find the sum of odd number
A program to find the sum of odd number In this section you will learn how to find the sum of odd number in the series up to the given number in java... to the number provided by user. Within the loop checking for odd number
Find out the prime number
Find out the prime number      ... to find out whether a given number is prime or not. Here we have used the 'for loop' statement and given the required condition for a prime number. As we know
how to find which user has modified the file
how to find which user has modified the file  how to find which user has modified the file
find factorial of any number using recursion
find factorial of any number using recursion  error in 14 line ; expected int rec( int a) ^ how to resolve this.please correct the code. import...)); System.out.println(?enter number?); int x=Integer.parseInt(br.readLine()); int result
Write a query to find the total number of rows in a table
Write a query to find the total number of rows in a table  Write a query to find the total number of rows in a table?   Hi, Here is the answer, we can find the total number of rows in a table using following query
Find Cylinder area By inputting value from user
Find Cylinder area By inputting value from user  Hello Sir I need... user and then calculate area using this radius value. Please provide me...); double radius; System.out.print("Please enter a radius
how to find square and cube of five number
how to find square and cube of five number  how to find square and cube of five number   Hi Friend, Try the following code: <html> <script> document.writeln("Square of 5 numbers:<br><br>
How do I find out the number of parameters passed into function9. ?
How do I find out the number of parameters passed into function9. ?  How do I find out the number of parameters passed into function9
How can we find the number of rows in a result set using PHP?
How can we find the number of rows in a result set using PHP?   How can we find the number of rows in a result set using PHP
Program to Find Cube Root of any Number without using built in function
Program to Find Cube Root of any Number without using built in function  Please help me in finding cube root of any number without using Built in function in java
How to find out the friend user between two columns in sql database
How to find out the friend user between two columns in sql database  Hi, Can any one please tell me ..how to find out the friend user between two columns in sql database? In other words i wanted to get the corresponding data from
Find User Home Directory
Find User Home Directory        In this example we are find user home directory. We..." as key to get the user define home directory
autogeneration of a random number and displaying it as a alert message to the user on clicking submit
automatically.But i want this number to be displayed when user click...autogeneration of a random number and displaying it as a alert message to the user on clicking submit  Hi, In my project order purchase system under
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
generate random numbers and display the largest
it. Write a method to find the largest value in an array. Write a program that takes... to the screen and uses your method to find the largest value in the array, then prints...]; } } System.out.println("Maximum Number is: "+ max
Write a program to find a factorial in any given number
; System.out.println("Enter the number to find the factorial"...Write a program to find a factorial in any given number This programming tutorial will teach you how to write a factorial of any given number
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
plz give me program to this: Given a string and a number ‘n’, find the ‘n’th distinct repeating character.
plz give me program to this: Given a string and a number ?n?, find the ?n?th distinct repeating character.    Given a string and a number ?n?, find the ?n?th distinct repeating character. For example, Input: Abracadabra, 1
2. Given a string and a number ‘n’, find the ‘n’th distinct repeating character.
2. Given a string and a number ?n?, find the ?n?th distinct repeating character.    Given a string and a number ?n?, find the ?n?th distinct repeating character. For example, Input: Abracadabra, 1 Abracadabra, 2 Abracadabra, 3
Advertisements
 

 

 

DMCA.com