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); } } }
3 odpowiedzi
+ 2
Try adjusting your loop parameter
for(int x=number; x>0;x--)
This will stop the iteration before it reaches 0
+ 1
Thank you, but the problem continues, I will try he Do While loop…
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