How i can fix the increasing order summation code?
- by user2971559
I want from the java to reads all numbers from the user as long as the number entered by user is bigger than the previous number. But i could write it for only positive numbers. How i can fix code below if all numbers included. If it is possible please write the solution for beginners because its my first year in computer science in college and I haven't learn a lot yet.
import acm.program.*;
public class IncreasingOrder extends ConsoleProgram {
public void run() {
int previousNumber = 0;
int total = 0;
int count = 0;
while(true) {
int n = readInt("Enter > ");
if (n <= previousNumber) break;
total += n;
count++;
previousNumber = n;
}
println("You have entered " + count + " numbers in increasing order.");
println("Sum of these " + count + " numbers is " + total + ".");
}
}