+ 3

Plz heeellpp!!!! What is prblem with this code

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc=new Scanner (System.in); int n=sc.nextInt(); for(int i=1;i<=n;i++) { if ( n %i=0) { int k=i; System.out.println("factors are"+k); } } } }

18th Mar 2017, 5:00 PM
niraj srivastava
niraj srivastava - avatar
8 Antworten
+ 4
// It is working now, try import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n=sc.nextInt(); for(int i=1;i<=n;i++) { if (n%i==0) { int k=i; System.out.println("factors are "+k); } } } } //Actually you put a space between Scanner and (System.in) on fifth line :-)
18th Mar 2017, 5:15 PM
Vishal Prajapati
+ 2
@niraj srivastava, What output you are getting and you are expecting? Kindly mention there.
18th Mar 2017, 5:02 PM
Vishal Prajapati
+ 2
it's an error in if statement and I want factors of the input no
18th Mar 2017, 5:04 PM
niraj srivastava
niraj srivastava - avatar
+ 2
you need to remove space in n. i.e. and use double euquls to ; if( n %i=0) replace to if(n%i==0)
18th Mar 2017, 5:06 PM
Vishal Prajapati
+ 2
sorry just corrected that but it's still getting error in main func
18th Mar 2017, 5:07 PM
niraj srivastava
niraj srivastava - avatar
+ 2
@niraj srivastava just use double equals to symbol in if statement. It will work. update : if(n%i==0)
18th Mar 2017, 5:09 PM
Vishal Prajapati
+ 2
already done bro it's not working
18th Mar 2017, 5:11 PM
niraj srivastava
niraj srivastava - avatar
+ 2
thanks it is working good
18th Mar 2017, 5:21 PM
niraj srivastava
niraj srivastava - avatar