Java programming problem with For Loop

Status
Not open for further replies.

DKasler

Baseband Member
Messages
36
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
    }
}
 
do you get any compile errors? if not, what is wrong with the output after you run it?
 
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.
 
Status
Not open for further replies.
Back
Top Bottom