Hi All,
I created this code in IntelliJ and tested, everything is working but I can't pass last requirement.
What is wrong?
Thx
Andrzej
package pl.codegym.task.task14.task1420;
/*
NWD
*/
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int pierwszaLiczba;
int drugaLiczba;
int NWD = 0;
try {
pierwszaLiczba = Integer.parseInt(reader.readLine());
drugaLiczba = Integer.parseInt(reader.readLine());
if (pierwszaLiczba < drugaLiczba) {
for (int i = 1; i < pierwszaLiczba; i++)
if (pierwszaLiczba % i == 0 && drugaLiczba % i == 0) {
NWD = i;
}
} else {
for (int i = 1; i < drugaLiczba; i++)
if (pierwszaLiczba % i == 0 && drugaLiczba % i == 0) {
NWD = i;
}
}
System.out.println(NWD);
} catch (Exception e) {
throw e;
}
if (pierwszaLiczba <= 0 || drugaLiczba <= 0) {
throw new Exception();
}
}
}