The Artima Developer Community
Sponsored Link

Java Answers Forum
Problem with code

2 replies on 1 page. Most recent reply: Jul 1, 2008 4:19 AM by saidon conteh

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 2 replies on 1 page
saidon conteh

Posts: 8
Nickname: conteh
Registered: Jun, 2008

Problem with code Posted: Jun 30, 2008 8:12 AM
Reply to this message Reply
Advertisement
Hi guys. Im certainly a newbie on the forum. Need help a lil bit with this code. It gives me an 'identifier expected' error when I compile the code. Would appreciate very much.

Here's the code....

public class LoopArguments
{
public static void main(String []args)
{
if(null == args || args.length < 1)
{
System.out.println("No arguments to print. Sorry.");
System.exit(1);
}

}//end the if block

//String message = new String();

String message = formatArguments(args);

message += formatArguments(args);
System.out.println(message);

}//end of the main method

public static String formatArguments(String msg[])
{
String myArgs = new String();
for(int i=0 ; i < msg.length ; i++)
{
myArgs += msg[ i ] + " ";
}//end the for statement

return myArgs;
}//end formatArguments method
}//end the class


George B

Posts: 24
Nickname: hmgeorge
Registered: Feb, 2008

Re: Problem with code Posted: Jun 30, 2008 12:10 PM
Reply to this message Reply
You have an extra close-curly in there. Here's the code reformatted with the extra curly removed. This compiles ok.

public class LoopArguments {
 
  public static void main(String []args) {
    if (null == args || args.length < 1) {
      System.out.println("No arguments to print. Sorry.");
      System.exit(1);
    }
    String message = formatArguments(args);
 
    message += formatArguments(args);
    System.out.println(message);
  }//end of the main method
 
  public static String formatArguments(String msg[]) {
    String myArgs = new String();
 
    for(int i=0 ; i < msg.length ; i++) {
      myArgs += msg[ i ] + " ";
    }//end the for statement
 
    return myArgs;
  }//end formatArguments method
}//end the class 
 

saidon conteh

Posts: 8
Nickname: conteh
Registered: Jun, 2008

Re: Problem with code Posted: Jul 1, 2008 4:19 AM
Reply to this message Reply
Thanks alot buddy, I don't know how I missed that....damn! It worked perfectly.

Flat View: This topic has 2 replies on 1 page
Topic: tic -tac-toe Previous Topic   Next Topic Topic: help..on Next n Previous Button

Sponsored Links



Google
  Web Artima.com   

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