-1
I came across a problem with the splitters of a number and that also goes to other problems
I made this code to print me number dividers from largest to smallest, but it is just printing one of the dividers. How can I solve this?
import java.util.Scanner;
public class ex1dd {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int x=0;
int y=0;
System.out.println("Dá-me 2 números");
x= sc.nextInt();
y=sc.nextInt();
for (int i =x;i<=y;i++) {
if (i %y == 0){
System.out.println(i);
}
}
}
}
If you want the dividers of
y
which are greater than or equal tox
then use:if (y % i == 0){
– anonimo
the problem for not exiting the expected result is in this line: "if (i % y == 0)" as it is a programming logic problem, try to solve, I guarantee you can! tip: use "System.out.println(i);" before if
– nunes
thanks @Nunes I’m just starting out in college and my teacher is really bad and I have to do at home, since you mentioned in programming logic some website tip or something to improve in that aspect
– Rui Simões