java programming giving "symbol error" -


import java.util.scanner;  class pyth{     public static void main(string[] args) {         system.out.println("enter n");         scanner in=new scanner(system.in);         int n=in.nextint();         {             for(int a=1;a>n;a++) {                 for(int b=a+1;b>n;b++) {                     int c=n-a-b ;                 }                 if(c*c=a*a+b*b) {                     system.out.println(a+','+b+','+c+',');                 }             }         }     } } 

i'm new programming, can't figure out problem. error:

pyth.java:15: error: cannot find symbol if(cc=aa+b*b)

^ symbol: variable c

location: class pyth

firstly, syntax important. maintain indents. makes code easier read , understand , helps in maintenance.

the errors in code :

  1. int c=n-a-b ; c being used in if comparison. needs declared beforehand. similarly, int b has declared before hand use in if statement.

  2. if(c*c=a*a+b*b) = assignment operator. use == make comparisons. , use more brackets rid of ambiguity.

additionally :

system.out.println(a+','+b+','+c+','); isnt mistake such, better use ",".

this should workd :

import java.util.scanner;  class pyth{     public static void main(string[] args){          system.out.println("enter n");          scanner in=new scanner(system.in);          int b,c;          int n=in.nextint();           for(int a=1;a>n;a++) {              for(b=a+1;b>n;b++)  {                  c=n-a-b ;              }               if(c*c==(a*a+b*b)) {                  system.out.println(a+","+b+","+c+",");              }          }     } } 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -