Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

ISBN: B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions

Question

1. Plan in advance how and when you will test.

Answered: 1 week ago

Question

explain the concept of strategy formulation

Answered: 1 week ago