Heeeelp!!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Heeeelp!!!

can u guys plz help me to create a prgrm in Java to input a no. and then take the factors of the no. (not print them) thanks

16th Mar 2017, 3:56 PM
niraj srivastava
niraj srivastava - avatar
5 Answers
+ 4
There is nothing to laugh, I had also started it one day :-) To get your factors, add this after for(input.....):- System.out.println(l); Hope to see you progress fast :-) Best of luck.
17th Mar 2017, 5:34 PM
Meharban Singh
Meharban Singh - avatar
+ 3
import java.util.Scanner; public class Program { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int input=sc.nextInt(); int count=0; for(int l=1;l<=input;l++){ if(input%l==0){ count++; } int[] arr=new int[count]; for(int x=0;x<arr.length;x++){ arr[x] = l; } } }}
18th Mar 2017, 4:36 PM
Meharban Singh
Meharban Singh - avatar
+ 2
Scanner sc=new Scanner (System.in); int input=sc.nextInt(); for(int l=1;l<=input;l++) if(input%l==0) //get your factors here
16th Mar 2017, 5:01 PM
Meharban Singh
Meharban Singh - avatar
0
plz tell me how to take the factors ..plz don't laugh actually I m really new to java
17th Mar 2017, 2:45 PM
niraj srivastava
niraj srivastava - avatar
0
bro I said not to print just like to take the factors into an array
18th Mar 2017, 4:12 PM
niraj srivastava
niraj srivastava - avatar