Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"For statement" need help? 1

Status
Not open for further replies.

tbarnes2788

Programmer
Feb 26, 2004
7
US
I have to debugg this program there is an error with the IF and FOR statement. Could some please expalin to me what's wrong?

public class FixDebugSix2
// Print the character values
// of 65 through 122
{
public static void main(String[] args)
{
char letter = a;
int a =0;
for(a = 65; a < 122; ++a)
{
letter = a;
System.out.print(" " + letter);
}
if(a = 85 && 105)
{
System.out.println();
}
System.out.println("\n End of program");
}

}
 
This looks like a school assignment, which is not allowed on this forum.

Code:
public class FixDebugSix2
// Print the character values
// of 65 through 122
{
   public static void main(String[] args)
   {
     int a =0;      // err 1 : declare a before using it
     char letter; // = (char)a;  // err 2 : possible loss of precision

     for(a = 65; a < 122; ++a)
       {
       letter = (char)a;// err 2 : possible loss of precision
       System.out.print("  " + letter);
       }
       //if( (a != 85) && (a != 105)) // what where you trying to do here ?
       //{
         System.out.println(a);
       // }
         System.out.println("\n End of program");
    }

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top