Page 1 of 1

Solution public static boolean negativeSum(Scanner in) { boolean neg = false; int sum = 0; int steps = 0; while(in.hasNe

Posted: Sun May 15, 2022 1:39 pm
by answerhappygod
Solution Public Static Boolean Negativesum Scanner In Boolean Neg False Int Sum 0 Int Steps 0 While In Hasne 1
Solution Public Static Boolean Negativesum Scanner In Boolean Neg False Int Sum 0 Int Steps 0 While In Hasne 1 (36.48 KiB) Viewed 53 times
**** Please answer with complete sentences and
explanation
Solution public static boolean negativeSum(Scanner in) { boolean neg = false; int sum = 0; int steps = 0; while(in.hasNextInt() && neg == false) { int token = in.nextInto; steps++; sum += token; if(sum < 0) { neg - true; } } if(neg == false) { System.out.println("no negative sum"); return false; } else { System.out.println(sum + " after + steps + " steps"); return true; } } 1 Answer the following: This solution works, but stylistically, it's meh. Identify at least two style choices here that are not ideal.