I'm writing a simple java code that takes two integers as min and max and a third integer as divisor and it finds all numbers between that are divisible by the third integer, which worked fine but in the output I can't get rid of the last comma.
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the first number: ");
int a = scanner.nextInt();
System.out.print("Enter the second number: ");
int b = scanner.nextInt();
System.out.print("Enter the divisor: ");
int d = scanner.nextInt();
for(int i=a; i<=b; i++) {
if(i%d == 0)
System.out.print(i+", ");
}
How could I do it?