The Artima Developer Community
Sponsored Link

Java Answers Forum
problem about using "while"

5 replies on 1 page. Most recent reply: Jul 21, 2006 5:52 AM by Ertan Toker

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Ertan Toker

Posts: 4
Nickname: blackeagle
Registered: Jul, 2006

problem about using "while" Posted: Jul 20, 2006 11:03 AM
Reply to this message Reply
Advertisement
i'm learning java programing, i want to use while term but there is an error : illegal start of type :( what can i do?


public class WhileOrnek {

int i = 0 ;
while (i < 5 ) {
System.out.println("i = " + i);
i++ ;

System.out.println("Sayma islemi tamamlandi.");
}
}


where is the mistake?


Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: problem about using "while" Posted: Jul 20, 2006 3:36 PM
Reply to this message Reply
The problem is that the code needs to be inside a method inside the class. Try the following:
public class WhileOrnek
{
    public static void main(String[] args)
    {
        int i = 0;
        while (i < 5 )
        {
            System.out.println("i = " + i++);
            System.out.println("Sayma islemi tamamlandi.");
        }
    }
}
(I haven't tried to compile the code so please forgive any syntax typos.)

Vince.

Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: problem about using "while" Posted: Jul 21, 2006 1:26 AM
Reply to this message Reply
A Turkish friend here has just translated the second println text for me, which suggests the following minor modification:
public class WhileOrnek
{
    public static void main(String[] args)
    {
        int i = 0;
        while (i < 5)
        {
            System.out.println("i = " + i++);
        }
        System.out.println("Sayma islemi tamamlandi.  (Counting process finished.)");
    }
}

Ertan Toker

Posts: 4
Nickname: blackeagle
Registered: Jul, 2006

Re: problem about using "while" Posted: Jul 21, 2006 5:48 AM
Reply to this message Reply
thanks:) problem solved;)

Ertan Toker

Posts: 4
Nickname: blackeagle
Registered: Jul, 2006

Re: problem about using "while" Posted: Jul 21, 2006 5:48 AM
Reply to this message Reply
thanks:) problem solved;)

Ertan Toker

Posts: 4
Nickname: blackeagle
Registered: Jul, 2006

Re: problem about using "while" Posted: Jul 21, 2006 5:52 AM
Reply to this message Reply
do you use msn?maybe we can talk there?

Flat View: This topic has 5 replies on 1 page
Topic: Legacy Code:  Don't you just love it! Previous Topic   Next Topic Topic: java game

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use