Question: Intro to JAVA Programming: The code is below the problem is that if I type in -1,-2,-4,32,-55,-17,75,-6,26,20,x it gives me 20 as the lowest which

Intro to JAVA Programming: The code is below the problem is that if I type in -1,-2,-4,32,-55,-17,75,-6,26,20,x it gives me 20 as the lowest which is not true, -55 is the lowest. What is wrong what needs to be fixed so that it includes negative numbers also? thank you.

import java.util.Scanner; /** * */ public class AmazonNetIncome { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("Enter net income or Q to quit: ");

int income = 0; int count = 0; double sum = 0; int numberCount = 0; double average = 0; int lowest = 0 ;

if(scan.hasNextInt()) { while(scan.hasNextInt()) { income = scan.nextInt(); numberCount++; lowest = income; sum = sum + income; if(income > 0) { count++; } else if (income < lowest) { lowest = income; } System.out.print("Enter net income or Q to quit: ");

} average = sum/numberCount; System.out.println(count); System.out.println(lowest); System.out.println(average);

} else { System.out.println("No values entered"); }

} }

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!