68 774
Assignments Done
Successfully Done
In January 2019

Answer to Question #55800 in Java | JSP | JSF for David

Question #55800
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.
Expert's answer
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();

System.out.println("Error:wrong number "+sc.next());


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions