write a program to input 10 integers and display the largest among them
Answers
JAVA CODE :
import java.util.*;
class largest_integer
{
public void main()
{
Scanner sc=new Scanner(System.in);
int a[]=new int[10];
System.out.println("Enter 10 numbers");
for(int i=0;i<10;i++)
{
a[i]=sc.nextInt();
}
int max=0;
for(int i=0;i<10;i++)
{
if(a[i]>max)
{
max=a[i];
}
}
System.out.println("The largest integer is :"+a[i]);
}
}
----------------------------------------------------------------------------
OUTPUT :
Enter 10 numbers
1
2
3
4
5
6
7
8
9
10
The largest integer is :10
Hope it helps
____________________________________________________________________
Question:
Write a program to input 10 integers and display the largest among them
Solution:
Languge used: Java
[ Without using array]
-------------------------------------------------------------------------------
import java.util.*;
public class Question
{
static void main()
{
Scanner sc=new Scanner(System.in);
int i,n,l=0;
System.out.println("Enter 10 integers:");
for(i=1;i<=10;i++)
{
n=sc.nextInt();
if(i==1)
l=n;
else if(n>l)
l=n;
}
System.out.println("Largest Number="+l);
}
}