Java String Array output error

import java.util.;
import java.lang.
;
class Employees
{
public void AddStaff()
{
for(int i=0;i<4;i++)
{
String s[]={new Scanner(System.in).next()};
}

			for(int i=0;i<4;i++)
			{
				System.out.println("The Staff is:"+s[i]);
			}
		}
}
class TestEmployee
{
	public static void main(String...arg)
		{
			Employees e=new Employees();
			e.AddStaff();
		}
}

//The question is i cannot get the String output on my screen it shows the error that Symbol s is not found/defined. please help me with a solution//

The variable s is only visible in the first loop. For the second loop to work you have to put it inside the first one. Another option would be to declare the variable s outside the loops so that the two loops can have access to the variable.

1 Like