Can someone help, supposed to use system.out.printf. Thank you 8. Write a method
ID: 674965 • Letter: C
Question
Can someone help, supposed to use system.out.printf. Thank you 8. Write a method called smallestlargest that accepts a Scanner for the console as a parameter and asks the user to enter numbers, then prints the smallest and largest of all the numbers supplied by the user.You may assume tha the user enters a valid number greater than o for the number of numbers to read. Here is a sample execution How many numbers do you want to enter?4 Number 1s5 Number 2s 11 Number 3:-2 Humber 4: 3 Smallest--2 Largest11Explanation / Answer
//Prompt a user to enter a series of integers separated by spaces
//and accept the input as a String. Display the list of integers
//and their sum. Save the file as SumIntegersInString.java.
import java.io.*;
import java.util.Scanner;
class SmallestLargest{
public static void main(String args[]){
Scanner in = new Scanner(System.in);
System.out.println("How many numbers do you want to enter");
String n = in.nextInt();
int numbers[] = new int[n];
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
for(int i = 0 ; i < n ; i++)
{
System.out.println("Number "+(i+1));
numbers[i] = in.nextInt;
if(numbers[i] < min)
min = numbers[i];
if(numbers[i] > max)
max = numbers[i];
}
System.out.println("Max: "+ max);
System.out.println("Min: "+ min);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.