Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: ';' expected?

  1. #1
    Junior Member
    Join Date
    Sep 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default ';' expected?

    ';' expected comes out when i compile, what's the problem with my while loop?
    btw..i know this is not the best solution for making a program find out if it is a prime or not..
    public class primenumberstesting2 {
    	public static void main(String[]args){
    		int num;
                          do{
                            }
    			while(num >=0){	
    			System.out.println("Enter a positive integral value: ");
    			 num = Keyboard.readInt();
     
    			 int isPrime=0;
     
            for(int num1=1;num1<=100;num1++)
                {
                    isPrime=0;
                    for(int num2=1;num2<num1;num2++) 
                        {
                            if(((num1%num2)==0) & num2!=1)
                            {
                               isPrime=1; 
                            }
                        }
                        if(isPrime==0)
                        {
                            System.out.println("Input is a prime number");
    					}else
    						System.out.println("Input is a non-prime number");
    			}
    					}
     
    		}
    	}
    Last edited by helloworld922; November 18th, 2009 at 07:31 PM.


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: ';' expected?

    This is because you have your do while statement wrong.

    This is what it should look like but you've got an extra { after the while() bit.

    do {
     // statement
    } while(condition);

    // Json
    Last edited by Json; November 19th, 2009 at 03:37 AM. Reason: Condition instead of statement, statement instead of logic :)

  3. #3
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,896
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: ';' expected?

    I think you meant this:

    do
    {
        // statements
    } while (condition);
    Last edited by helloworld922; November 21st, 2009 at 02:11 PM.

  4. #4
    Junior Member
    Join Date
    Sep 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: ';' expected?

    i placed that do because ..there's another error if i wont have it...something likE.... "num wont be able to initiallize"

  5. #5
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: ';' expected?

    Quote Originally Posted by noobish View Post
    i placed that do because ..there's another error if i wont have it...something likE.... "num wont be able to initiallize"
    You need to initialize the num variable to something before you enter the loop, something like
    int num = 0;
    do....
    while...

Similar Threads

  1. [SOLVED] Java error "Another <identifier> expected"
    By bruint in forum What's Wrong With My Code?
    Replies: 23
    Last Post: May 1st, 2009, 08:47 AM