Java Homework - Compilation Error

Discussion in 'Mac Programming' started by mcmacmcmac, Oct 30, 2007.

  1. macrumors member

    Joined:
    Oct 2, 2007
    #1
    Hey guys, when I try to compile this I get 1 error.. but i don't get it, I don't think I'm suppose to have a ; at the end of that line and when i put it, i get another error.. i'd really appreciate any help with this!

    java:27: ';' expected
    While (testVariable != -1)

    1 error



    Tool completed with exit code 1


    Code:
    import java.util.Scanner; // program uses class Scanner
    
    public class Factors2
    {
    
    	public static void main(  String args[]  )
    
    	{
    
    		System.out.println( "Student Name: Bob\nStudent Number: 999\n\n" );
    
    		// create Scanner to obtain input from command window
    		Scanner input = new Scanner ( System.in );
    
    		int testVariable; // variable entered by user
    		int factorCounter; // factors to divide into the test variable to solve for primitive values
    		double testFactor; // result of dividing the factor counter into the test variable
    
    
    
    		// prompt for input and read integer from user
    		System.out.print("Enter a positive integer number or -1 to quit:");
    		testVariable = input.nextInt();
    
    
    		// loop until sentinel value read from user
    		While (testVariable != -1)
    		{
    			for (factorCounter = testVariable; factorCounter >= 0; factorCounter--)
    			{
    				testFactor = (testVariable / factorCounter);
    
    				System.out.printf("%.2f, %d", testFactor, factorCounter);
    
    			} // end for
    
    			// prompt for input and read next grade from user
    			System.out.print("Enter a poisitive integer number or -1 to quit");
    			testVariable = input.nextInt();
    
    
    		} // end while
    
    		if (testVariable == -1)
    		{
    			System.out.println("Press any key to continue . . .");
    		} // end if
    
    	} // end main method
    
    } // end class Factors
     
  2. macrumors 6502a

    Joined:
    Dec 4, 2006
    Location:
    Katy, Texas
  3. thread starter macrumors member

    Joined:
    Oct 2, 2007
    #3
    LOL brilliant thanks man!
     

Share This Page