Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2009
    Posts
    90
    Rep Power
    0

    Default [SOLVED] what error do i have?

    variable a might not have been initialized
    if ((12000 <= a )&&(a < 12321)){
    ^
    what is this mean?
    Java Code:
    public class tt{
    	public static void main(String[]args){
    
    	int n = 1;
    
    	double a;
    
    	while ( n < 999)
    
    		 a = Math.pow(n, 2);
    
    		if ((12000 < a )&&(a < 12321)){
    
    			System.out.println("The smallest n such that n^2 > 12,000 is " + n);
    }
    		n++;
    
    	}
    }
    im learning about loops at this point.
    Last edited by PureAwesomeness; 01-29-2009 at 05:03 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    There is only one variable in that line that trips the error. You have declared the variable, but where have you initialized it -- where have you set its initial value? Bottom line: when declaring variables (not counting variables declared in the class scope), you need to initialize them to something at declaration.

  3. #3
    Join Date
    Jan 2009
    Posts
    90
    Rep Power
    0

    Default

    so i need to assign a to something like a number first?

  4. #4
    Join Date
    Jan 2009
    Posts
    90
    Rep Power
    0

    Default

    ok i got it thanks

  5. #5
    angryboy's Avatar
    angryboy is offline Senior Member
    Join Date
    Jan 2009
    Posts
    742
    Rep Power
    6

    Default

    glad your prob is solved.
    if solved, please mark it as solved by using Thread Tools at the top toolbars.
    USE CODE TAGS--> [CODE]...[/CODE]
    Get NotePad++ (free)

  6. #6
    angryredantz is offline Member
    Join Date
    Jan 2009
    Posts
    6
    Rep Power
    0

    Default

    I try the code as posted and after assing a value to the variable a, it still missing the opening and closing brackets {} for the while loop.

Similar Threads

  1. Replies: 3
    Last Post: 01-23-2009, 09:53 AM
  2. error 530 error authentication required
    By rgale in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 05-12-2008, 05:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •