需求说明:
输入一个整数,输出所有能整除该整数的结果:
实现代码:
package demo; import java.util.Scanner; public class test1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入一个整数:"); int num = sc.nextInt(); System.out.println("---------------------------"); System.out.println("能整除"+num+"的数字有:"); for (int i = 1; i <= num; i++) { if (num%i==0) { System.out.println(i); } } } }