+ 1
Whats the problem in this code ? Pls tell..
public class Program { public static void main(String args [int n]) {double d=0,c=0,S=0; for(double i=n;i>=0;i=i/10) { d=i%10;c=Math.pow(d,3.0); S=S+c;} if(S==n) {System.out.print("Armstrong no");} else {System.out.print("Not an armstrong no.");} } }
6 Answers
+ 3
1. as @shobhit stated the signature for the main method should look like:
public static void main(String args [])
remove int n from between the brackets and place it in the body of the method.
2. Where are you expecting to get the value for n? It has not been set. User input via a Scanner? Command line? etc
+ 2
@aizada no int n would not be automatically set to 0 in c.
+ 1
don't declare int n inside brackets of args. Declare it outside.
0
When it's type of double I think you should declare it like this: double d =0.0, c=0.0, S=0.0
Oh and maybe put that int n after the Main method. plus when it's S==n there can be a round off error
I t ink I don't know I'm just a student who is learning đ
0
I thought if you put : int n; would that set to zero automatically or no?
0
@shobhit oh ok thank you