top of page
// yanlış input girdiğimizde program sonlanmaz biz sonlandırana kadar devam eder.
package alıştırmalar;
import java.util.InputMismatchException;
import java.util.Scanner;
public class exercise12_2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
while (true) {
try {
sum();
} catch (InputMismatchException ex) {
System.out.println("HATA!! LÜTFEN SAYI GİRİN!! " + ex);
}
}
}
public static void sum() throws InputMismatchException {
Scanner input = new Scanner(System.in);
System.out.println("2 sayı girin ");
double x = input.nextDouble();
double y = input.nextDouble();
System.out.println(x + "+" + y + "= " + (x + y));
}
}
bottom of page