Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Java programming problem with For Loop
Closed Thread
Old 08-04-2004, 04:31 PM   #1 (permalink)
 
Newb Techie

Join Date: Mar 2004

Posts: 36

DKasler

Send a message via AIM to DKasler Send a message via Yahoo to DKasler
Default Java programming problem with For Loop

Can anyone tell me what is wrong with this For Loop?

Code:
public class EmployeeApplication
{
   public static void main(String[] args)
    {
      //define variables
      Employee obj;   //the object of Employee class
      String sSource = args[0]; 
      /* if you have multiple inputs you can use for loop
      * to take all inputs one by one
      */
     for( int i = 0; i < sSource.length(); i++)
      {
        obj = sSource[];
      }
 
      String s1 = sSource.substring(0, 11);  //SSN
      String s2 = sSource.substring(12,sSource.length()); //Name
 
      //create an instance of each variable
      obj = new Employee();
 
      //calling the methods of the first object
      obj.setsEmpId(s1);
      obj.setsEmpName(s2);
 
      System.out.println(obj); //toString is automatically called
    }
}

DKasler is offline  
Old 08-04-2004, 06:49 PM   #2 (permalink)
 
Super Techie

Join Date: Jul 2004

Posts: 398

kostas

Default

do you get any compile errors? if not, what is wrong with the output after you run it?
__________________

kostas is offline  
Old 08-05-2004, 08:01 AM   #3 (permalink)
 
Ultra Techie

Join Date: Sep 2003

Location: Bamberg, Germany

Posts: 549

Iron_Cross

Send a message via ICQ to Iron_Cross Send a message via MSN to Iron_Cross Send a message via Yahoo to Iron_Cross
Default

Try this:
Code:
public class EmployeeApplication
{
   public static void main(String[] args)
    {
      //define variables
      Employee obj;   //the object of Employee class
      String sSource = args[0]; 
      /* if you have multiple inputs you can use for loop
      * to take all inputs one by one
      */
     for( int i = 0; i < sSource.length(); i++)
      {
        obj = sSource[i];
      }
 
      String s1 = sSource.substring(0, 11);  //SSN
      String s2 = sSource.substring(12,sSource.length()); //Name
 
      //create an instance of each variable
      obj = new Employee();
 
      //calling the methods of the first object
      obj.setsEmpId(s1);
      obj.setsEmpName(s2);
 
      System.out.println(obj); //toString is automatically called
    }
}
See if that works, all I did was change this line:
obj = sSource[i];
I added the i.
__________________

See today\'s Penny-Arcade!(May contain foul lanuage)
Pain is weakness leaving the body.

PM Me for my MSN
Iron_Cross is offline  
Old 08-05-2004, 09:37 AM   #4 (permalink)
 
Super Techie

Join Date: Aug 2003

Posts: 332

soundgarden

Send a message via AIM to soundgarden
Default

obj = sSource[];

should be

obj=sSource[i];

edit...

lol Iron_Cross, i didnt read your post.
soundgarden is offline  
Old 08-05-2004, 03:54 PM   #5 (permalink)
 
Ultra Techie

Join Date: Sep 2003

Location: Bamberg, Germany

Posts: 549

Iron_Cross

Send a message via ICQ to Iron_Cross Send a message via MSN to Iron_Cross Send a message via Yahoo to Iron_Cross
Default

It's all good, I've done that plenty of times 8)
__________________

See today\'s Penny-Arcade!(May contain foul lanuage)
Pain is weakness leaving the body.

PM Me for my MSN
Iron_Cross is offline  
Old 09-14-2004, 10:49 AM   #6 (permalink)
 
Newb Techie

Join Date: Mar 2004

Posts: 36

DKasler

Send a message via AIM to DKasler Send a message via Yahoo to DKasler
Default

Thanks alot guys. Seems good now.
DKasler is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On