None of the requirement is good.
package pl.codegym.task.task14.task1420;
import java.util.Scanner;
/*
NWD
*/
public class Solution {
public static void main(String[] args) throws Exception {
nwd();
}
public static void nwd(){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int m = 0;
if(a < 0 || b < 0){
throw new IllegalArgumentException("Liczby muszą być dodatnie") ;
}
if (a < b){
m = a;
} else {
m = b;
}
while(true || m == 0){
m--;
if(a % m == 0 && b % m == 0){
System.out.println(m);
break;
}
}
}
}