package ejercicio2;
import java.util.Scanner;
public class Suma {
public static void main(String[] args) {
int n = 0;
int s = 0;
String value = null;
do {
Scanner keyboard = new Scanner(System.in);
System.out.print("Numero: ");
value = keyboard.next();
n = Integer.parseInt(value);
s += n;
} while (n != 0);
System.out.format("La suma de los numeros es: %d\n", s);
}
}
La solución presentada no es 100% correcta, falta el tratamiento de excepciones para capturar el error (generado al escribir un caracter cuando se espera un entero), crear la función total y pasar el parámetro por referencia.
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.