0
Why do I see no output?
import java.util.Scanner; public class Mazrab5 { public static void main(String[]args) { Scanner scanner=new Scanner(System.in); int a=scanner.nextInt(); int b=scanner.nextInt(); for (int i=a++; i<b ; i++) { if ( i%5==0) { System.out.println(i); } } scanner.close(); } }
4 Respostas
+ 3
Hello Dorsa
Your code works.
If you enter 0 and 6 for a and b you will get 0 and 5 as output.
0 % 5 = 0
5 % 5 = 0
+ 1
Thanks a lot for your attention.
0
Oh yes! You are right.Thanks a lot.
I just checked it again,but i dont know why it says no output on my computer , but it is correct on my phone
0
Dorsa
Maybe because of a++
I never tested it but I guess it causes troubles and maybe it creates an undefinded situation (it depends on your compiler what happens).
To increment i you have i++
But you also change i via a++
I would try to print all numbers and see if you overjump numbers.
Btw: I think it is not a good practice to manipulate the start or the end condition while the loop is running.