+ 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.");} } }

12th Mar 2018, 3:42 AM
Akshat Agarwal
Akshat Agarwal - avatar
6 Réponses
+ 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
12th Mar 2018, 4:56 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
@aizada no int n would not be automatically set to 0 in c.
14th Mar 2018, 7:34 AM
shobhit
shobhit - avatar
+ 1
don't declare int n inside brackets of args. Declare it outside.
12th Mar 2018, 4:30 AM
shobhit
shobhit - avatar
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 😁
14th Mar 2018, 7:00 AM
Aiza & Sharik
Aiza & Sharik - avatar
0
I thought if you put : int n; would that set to zero automatically or no?
14th Mar 2018, 7:03 AM
Aiza & Sharik
Aiza & Sharik - avatar
0
@shobhit oh ok thank you
14th Mar 2018, 5:42 PM
Aiza & Sharik
Aiza & Sharik - avatar