anyone can please answer
Attachments:
Dårviñ714:
Want to write the full program or just the logic
Answers
Answered by
1
import java.util.*;
class Brainly
{
public static void main(String args[])
{
int a,b,c,i;
int demo[] = new int[10];
Scanner scan = new Scanner(System.in);
System.out.println("Enter number of integers: ");
a = scan.nextInt();
System.out.println("Enter the number of elements one by one: ");
for(i=0;i<a;i++)
{
demo[i] = Scan.nextInt();
}
b = c = demo[0];
for(i=1;i<a;i++)
{
if(demo[i]>b)
b=demo[i];
else if(demo[i]<c)
c=demo[i];
}
System.out.println("The largest number is: "+b);
System.out.println("The smallest number is: "+c);
}
}
Hope this helps!
class Brainly
{
public static void main(String args[])
{
int a,b,c,i;
int demo[] = new int[10];
Scanner scan = new Scanner(System.in);
System.out.println("Enter number of integers: ");
a = scan.nextInt();
System.out.println("Enter the number of elements one by one: ");
for(i=0;i<a;i++)
{
demo[i] = Scan.nextInt();
}
b = c = demo[0];
for(i=1;i<a;i++)
{
if(demo[i]>b)
b=demo[i];
else if(demo[i]<c)
c=demo[i];
}
System.out.println("The largest number is: "+b);
System.out.println("The smallest number is: "+c);
}
}
Hope this helps!
Attachments:
Answered by
2
HELLO FRIEND!
Rajdeep here....
__________________________________________
ICSE standard question.
Here's the program code:
import java.util.Scanner;
class MaxMin
{
public static void main (String args[])
{
Scanner sc = new Scanner (System.in);
int num[] = new int[10];
int i, max, min;
System.out.println("Enter 10 numbers, one by one: ");
for (i = 0; i < 10; i++)
{
num[i] = sc.nextInt();
}
max = num[0];
min = num[0];
for (i = 0; i < 10; i++)
{
if(num[i] > max)
{
max = num[i];
}
if (num[i] < min)
{
min = num[i];
}
}
System.out.println("The greatest number in the array is " + max);
System.out.println("The smallest number in the array is " + min);
} //End of main()
} //End of class
Rajdeep here....
__________________________________________
ICSE standard question.
Here's the program code:
import java.util.Scanner;
class MaxMin
{
public static void main (String args[])
{
Scanner sc = new Scanner (System.in);
int num[] = new int[10];
int i, max, min;
System.out.println("Enter 10 numbers, one by one: ");
for (i = 0; i < 10; i++)
{
num[i] = sc.nextInt();
}
max = num[0];
min = num[0];
for (i = 0; i < 10; i++)
{
if(num[i] > max)
{
max = num[i];
}
if (num[i] < min)
{
min = num[i];
}
}
System.out.println("The greatest number in the array is " + max);
System.out.println("The smallest number in the array is " + min);
} //End of main()
} //End of class
Attachments:
Similar questions