+ 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); } } } }
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 :-)
+ 2
@niraj srivastava, What output you are getting and you are expecting? Kindly mention there.
+ 2
it's an error in if statement and I want factors of the input no
+ 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)
+ 2
sorry just corrected that but it's still getting error in main func
+ 2
@niraj srivastava just use double equals to symbol in if statement. It will work. update :
if(n%i==0)
+ 2
already done bro it's not working
+ 2
thanks it is working good