0

Problemas resultado practica 18.3 Java

Necesito ayuda en esta practica : import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int number = read.nextInt(); //tu código va aquí for (int x=number; x >= 0; x--){ if (x%3==0){ /*no puedo obtener el resultado porque cero es multiplo de 3, en el resultado esperado aparece cero, por lo demás todo estaría ok*/ continue; } System.out.println(x); } } }

31st Aug 2021, 11:06 AM
Ruben Morante
Ruben Morante - avatar
3 odpowiedzi
+ 2
Try adjusting your loop parameter for(int x=number; x>0;x--) This will stop the iteration before it reaches 0
31st Aug 2021, 11:27 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 1
Thank you, but the problem continues, I will try he Do While loop…
1st Sep 2021, 8:43 AM
Ruben Morante
Ruben Morante - avatar
0
Finally I found this way: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int number = read.nextInt(); //your code goes here do { if (number == 0) { System.out.println(number); break; } else if (number % 3 == 0) { number--; continue; } else { System.out.println(number); number--; } } while (number >= 0); } } something is wrong. ok, it works, but I feel there is better way to the same result
31st Oct 2021, 1:55 PM
Ryszard Orlicki
Ryszard Orlicki - avatar