Extend the Main method in such a way that repeatedly values could be read, till number 0 is given. Then the programme is finished. Before that the sum of all read in figures is still given, if all readable Values were integral numbers. In all other cases nothing is given.
1
Expert's answer
2015-11-03T00:00:47-0500
import java.util.Scanner; public class MainClass {
public static void main(String[] args) { Scanner sc = new Scanner(System.in); int sum=0;
while (true) { System.out.println("Enter integer number or 0 for exit"); if (sc.hasNextInt()) { int inputNumber = sc.nextInt(); if(inputNumber==0){ break; }else{ sum=sum+inputNumber; }
}else{ System.out.println("Error:wrong number "+sc.next()); } } System.out.println("sum="+sum); }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment