Computers |
|
| | #1 (permalink) |
| Newb Techie | 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
}
} |
| | |
| | #3 (permalink) |
| Ultra Techie | 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
}
} 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 |
| | |
| | #5 (permalink) |
| Ultra Techie | 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 |
| | |