Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Loops errors
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
slider203




PostPosted: Wed Mar 03, 2010 7:46 pm   Post subject: Loops errors

Hello I have 2 porgrams that I can find the error with

the first

class Loops1
{
public static void main (string args [])
{
System.out.println ("Loops1")
int b = 0;
int MAX1 = 13;
int increment = 2;
for i = 1; i <= MAX1; i+= increment)
{
System.out.println (i);
b = i;
}
System.out.println ("After the loop b = "+b+".");
}
}

The second program is:

class Loops2
{
public static void main (string args [])
{
System.out.println ("Loops2")
int c=1;
do
{
System.out.print (c+" ");
c-=1;
}
while (c<5);
System.out.println ("\nAfter the loop c = "c+".");
}
}

Any help is greatly appreciated.
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Wed Mar 03, 2010 8:05 pm   Post subject: RE:Loops errors

In the first one, you're missing an open bracket after for.

In the second one, you have an upper bound on c, but c is decreasing.

In both cases, it should be String[] args, not String args[].
TheGuardian001




PostPosted: Wed Mar 03, 2010 8:46 pm   Post subject: Re: RE:Loops errors

DemonWasp @ Wed Mar 03, 2010 8:05 pm wrote:

In both cases, it should be String[] args, not String args[].


Java actually accepts either one, although type[] name does make more logical sense (to me at least).
DemonWasp




PostPosted: Thu Mar 04, 2010 12:03 pm   Post subject: RE:Loops errors

Ah, right. Maybe I'm confusing that with C/C++ (they do make that distinction, right?).
Barbarrosa




PostPosted: Thu Mar 04, 2010 11:38 pm   Post subject: Re: Loops errors

You also seem to be missing semicolons after:
Java:

System.out.println ("Loops1")

and
Java:

System.out.println ("Loops2")



These should be:
Java:

System.out.println ("Loops1");

and
Java:

System.out.println ("Loops2");

respectively.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: