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

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

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

Post 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 54 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.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply