Question: [Java] I'm not sure what I am doing wrong here. Complete the application, DecisionsWithInput to read a set of integers. Stop reading input when a

[Java] I'm not sure what I am doing wrong here.

Complete the application, DecisionsWithInput to read a set of integers. Stop reading input when a non-integer is read. Use this exact prompt: System.out.print("Enter an integer or Q to quit: ");

Note: you will actually quit on any non-integer.

Do the following things

Find and print the sum of all the odd numbers

Find and print the smallest of the inputs

Determine if the number 5 is in the input. Print "5 is my lucky number" if it is in the inputs otherwise print "no fives"

Print the number of values that are positive (greater than 0)

You will only read the inputs one time and do all the processing as you go. No arrays yet.

The outputs should be on separate lines and in the order given above. If there were no inputs, just print "no input"

[Here's my code]

import java.util.Scanner; /** * Get a set of integers and print some infor about them */ public class DecisionsWithInput { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int counter = 0; int input = 0; int sum = 0; int min = 0; int positive = 0; boolean first = true, isFive = false; System.out.print("Enter an integer or Q to quit: "); while(scan.hasNextInt()) { System.out.print("Enter an integer or Q to quit: "); input = scan.nextInt(); if(first) { min = input; first = false; } if(min > input) { min = input; } if(input % 2 == 1) { sum = sum + input; } if(input > 0) { positive = input; } if(input == 5) { isFive = true; } counter++; } if(scan.hasNextInt()) { System.out.println(sum); System.out.println(min); if(!isFive) { System.out.println("no fives"); } else { System.out.println("5 is my lucky number"); } System.out.println(positive); } else { System.out.println("No Input"); } } }

Please check your code using the link below. It has to exact same with the tester. Thank you.

http://www.codecheck.it/files/16122506408qzehhu15mi3hj2y4c9fnqwjd

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!