public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter a Number : "); int input = scan.nextInt(); int array[] = new int[10]; int j=0; int x = 0; for (int i = 1; i <= input ; i++){ j += 1; if (input % j == 0){ array[x++] = j ; } } System.out.println("the number divisble by: "); for (int k:array){ if (k != 0){ System.out.print(array[k]); } } } }[COLOR="Silver"] --- Update --- [/COLOR]public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter a Number : "); int input = scan.nextInt(); int array[] = new int[10]; int j=0; int x = 0; for (int i = 1; i <= input ; i++){ j += 1; if (input % j == 0){ array[x++] = j ; } } System.out.println("the number divisble by: "); for (int k:array){ if (k != 0){ System.out.print(array[k]); } } } }
--- Update ---
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter a Number : ");
int input = scan.nextInt();
for ( int i = 1 ; i<=input ; i++){
if ( input%i == 0 ){
System.out.println(i);
}
}
}
}