answersLogoWhite

0

{

// set up our input buffer

BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

String currentLine;

// store our ints in a list

int smallest = 0;

int largest = 0;

// counter

int numIntsRead = 0;

// force smallest and largest to start as the first proper int entered

while (numIntsRead < 1) {

currentLine = in.readLine();

try {

// convert from string to int

int currentNumber = Integer.parseInt(currentLine);

smallest = currentNumber;

largest = currentNumber;

++numIntsRead;

} catch (final NumberFormatException ex) {

// we go here if the user didn't type in an integer

}

}

// loop until we read all 5 ints

while (numIntsRead < 5) {

currentLine = in.readLine();

try {

// convert from string to int

int currentNumber = Integer.parseInt(currentLine);

if (currentNumber < smallest) {

smallest = currentNumber;

}

if (currentNumber > largest) {

largest = currentNumber;

}

++numIntsRead;

} catch (final NumberFormatException ex) {

// we go here if the user didn't type in an integer

}

}

// display our findings

System.out.println("Smallest:\t" + smallest);

System.out.println("Largest:\t" + largest);

}

User Avatar

Wiki User

16y ago

What else can I help you with?

Continue Learning about Engineering

Write a program that randomly fills a 10 component array then prints the largest and smallest values in the array?

final double[] ns = new double[10]; final Random rnd = new Random(System.currentTimeMillis()); // Fill... for (int i = 0; i &lt; ns.length; ++i) { ns[i] = rnd.nextDouble(); } // Get largest/smallest... double largest = Double.MIN_VALUE; double smallest = Double.MAX_VALUE; for (double n : ns) { if (n &gt; largest) { largest = n; } if (n &lt; smallest) { smallest = n; } } // largest and smallest are now the proper values.


Write a C program that will ask the user for 4 integer values and then produce the following output 1 The sum of the four numbers 2 The sum of the first two numbers minus the sum of the las?

#include&lt;stdio.h&gt; main() { int a,b,c,d; // The four integers to be asked printf("Give the first integer: "); //asks for the first integer scanf("%d",&amp;a); // puts the user input in the address of the integer "a" printf("Give the second integer: "); //same explanations scanf("%d",&amp;b); printf("Give the third integer: "); scanf("%d",&amp;c); printf("Give the fourth integer: "); scanf("%d",&amp;d); printf("1. The sum of the four integers is: %d",a+b+c+d); //prints the sum of the four integers given by the user, notice the "a+b+c+d" at the end) printf("2. The sum of the first two numbers minus the sum of the last: %d",a+b-c-d); //prints the second condition by putting the correct operations return 0; //ends the program } I never tested this program though, but i think it would work.


Write a program that input a positive integer and prints a triangle using for loop?

write a program that reads in the size of the side of square and then pints a hollow square of that size out of asterisks and blanks?


How do you create a flowchart that will accept a number and print the integers and the product of the integers of the number?

Oh, dude, creating a flowchart for that is like making a peanut butter and jelly sandwich - easy peasy. You just gotta start with a diamond shape for the decision-making process, then add rectangles for the input/output and calculations. Like, you'll have one box for accepting the number, another for calculating the product of the integers, and a final one for printing the result. It's like drawing a map to the land of math!


Write a function that reads an integer and determines and prints how many digits in the integer are 7s?

== == // Returns number of 7s in num. int numSevens(int num) { int _num = num; int numSevens = 0; while( _num &gt; 0 ) { if( (_num % 10) == 7 ) { ++numSevens; } _num /= 10; } return numSevens; }

Related Questions

Write a program that randomly fills a 10 component array then prints the largest and smallest values in the array?

final double[] ns = new double[10]; final Random rnd = new Random(System.currentTimeMillis()); // Fill... for (int i = 0; i &lt; ns.length; ++i) { ns[i] = rnd.nextDouble(); } // Get largest/smallest... double largest = Double.MIN_VALUE; double smallest = Double.MAX_VALUE; for (double n : ns) { if (n &gt; largest) { largest = n; } if (n &lt; smallest) { smallest = n; } } // largest and smallest are now the proper values.


Write a C program that will ask the user for 4 integer values and then produce the following output 1 The sum of the four numbers 2 The sum of the first two numbers minus the sum of the las?

#include&lt;stdio.h&gt; main() { int a,b,c,d; // The four integers to be asked printf("Give the first integer: "); //asks for the first integer scanf("%d",&amp;a); // puts the user input in the address of the integer "a" printf("Give the second integer: "); //same explanations scanf("%d",&amp;b); printf("Give the third integer: "); scanf("%d",&amp;c); printf("Give the fourth integer: "); scanf("%d",&amp;d); printf("1. The sum of the four integers is: %d",a+b+c+d); //prints the sum of the four integers given by the user, notice the "a+b+c+d" at the end) printf("2. The sum of the first two numbers minus the sum of the last: %d",a+b-c-d); //prints the second condition by putting the correct operations return 0; //ends the program } I never tested this program though, but i think it would work.


Writing a program which prints a text of 4 lines consisting of characters integer values and floating point values using print statement?

To write a program that prints a text of 4 lines consisting of integer and floating point values, you can use formatted strings in Python. Here's a simple example: int_value = 42 float_value = 3.14 print(&quot;Line 1: Integer value is&quot;, int_value) print(&quot;Line 2: Float value is&quot;, float_value) print(&quot;Line 3: Sum of values is&quot;, int_value + float_value) print(&quot;Line 4: Float value to two decimals is {:.2f}&quot;.format(float_value)) This code snippet prints four lines, showcasing both integer and floating point values.


Write a C program that prompts the user for three decimal numbers and prints them trimmed as integer values. For example, if the user informs the values 13.2, 12.5, 102.231, the program prints out 13, 12, 102?

Here's a simple C program that prompts the user for three decimal numbers, converts them to integers, and prints the trimmed integer values: c Copy code #include int main() { double num1, num2, num3; // Prompt the user for three decimal numbers printf(&quot;Enter three decimal numbers: &quot;); scanf(&quot;%lf %lf %lf&quot;, &amp;num1, &amp;num2, &amp;num3); // Convert and print the trimmed integer values int intNum1 = (int)num1; int intNum2 = (int)num2; int intNum3 = (int)num3; printf(&quot;Trimmed integer values: %d, %d, %d\n&quot;, intNum1, intNum2, intNum3); return 0; } In this program: We declare three variables num1, num2, and num3 to store the decimal numbers entered by the user. We use printf to prompt the user to enter three decimal numbers. We use scanf to read and store the user's input in the variables num1, num2, and num3. We then convert these decimal numbers to integers by casting them using (int) and store them in intNum1, intNum2, and intNum3. Finally, we use printf again to print the trimmed integer values. Compile and run the program, and it will prompt you for three decimal numbers and print their trimmed integer values as requested.


How much maximum value Us dollar note?

The largest denomination of currency the US prints today is the $100 bill.


Write a program that input a positive integer and prints a triangle using for loop?

write a program that reads in the size of the side of square and then pints a hollow square of that size out of asterisks and blanks?


Who is Thomas prints?

thomas prints invented prints


How do you create a flowchart that will accept a number and print the integers and the product of the integers of the number?

Oh, dude, creating a flowchart for that is like making a peanut butter and jelly sandwich - easy peasy. You just gotta start with a diamond shape for the decision-making process, then add rectangles for the input/output and calculations. Like, you'll have one box for accepting the number, another for calculating the product of the integers, and a final one for printing the result. It's like drawing a map to the land of math!


What is definition for dry wet prints?

wet prints are those in which fabri is either dyed or printed dry prints are the fancy prints like flock prints, burn out prints.


Difference between percent p and percent x in c language?

%p prints a pointer, %x prints an integer. They may be similar, but not the same. Eg.printf ("ptr=%p int=%d\n", main, (int)main);DOS: ptr=0F01:0010 int=10Windows: ptr=:0F010010 int=F010010


How can Implement JAVA code which takes 2 dimensional integer array as input and prints out heaviest island?

public static void main (String args[]) throws IOException { int abc = System.in.read(); }


Write a function that reads an integer and determines and prints how many digits in the integer are 7s?

== == // Returns number of 7s in num. int numSevens(int num) { int _num = num; int numSevens = 0; while( _num &gt; 0 ) { if( (_num % 10) == 7 ) { ++numSevens; } _num /= 10; } return numSevens; }