Hi guys,
Program throws good error message when i write String for example, It prints proper numbers but says "The program ran too long and was closed!" when try to verify. Any suggestions?
package pl.codegym.task.task14.task1420;
/*
NWD
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int []tab=new int[2];
try{
for(int i=0;i<2;i++)
{
String input= reader.readLine();
tab[i]=Integer.parseInt(input);
}
while (tab[0] != 0 && tab[1] != 0) {
if (tab[0] < tab[1]) {
tab[1] = tab[1] - tab[0];
} else {
tab[0] = tab[0] - tab[1];
}
}
if (tab[1] > tab[0]) {
System.out.println(tab[1]);
} else {
System.out.println(tab[0]);
}
}catch (NumberFormatException e){
System.out.println("Zły typ danych");
}
}
}