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
**** 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.
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.