Write a program to input 10 integers and display the largest as well as the smallest integer
PLEASE GIVE ANSWER IN JAVA.....
Answers
Answer:
if(i==0&&num>0)
small=num;
if(num<small)
small=num;
System.out.println(small);
}
Explanation:
d get the largest without using arrays but, unable to get the smallest one.
public static void main(String[] args)
{
int smallest=0;
int large=0;
int num;
System.out.println("enter the number");
Scanner input=new Scanner(System.in);
int n=input.nextInt();
for(int i=0;i<n;i++)
{
num=input.nextInt();
if(num>large)
{
large=num;
}
System.out.println("the largest is:"+large);
//gives the largest number in n numbers
Program: {JAVA}
import java.util.*;
public class Brainly
{
static void main()
{
Scanner sc=new Scanner(System.in);
int i,n,l=0,s=0;
System.out.println("Enter 10 integers:");
for(i=1;i<=10;i++)
{
n=sc.nextInt();
if(i==1)
s=l=n;
if(n>l)
l=n;
if(n<s)
s=n;
}
System.out.println("Largest Number="+l);
System.out.println("Smallest Number="+s);
}
}