Hello guys. I've written a simple program as below that gets names from user and holds them into method.
Main
Code:
import java.util.Scanner;
public class TestProject
{
public static void main(String[] args)
{
writing input = new writing();
Scanner keyboard = new Scanner(System.in);
for (int i = 0; i < 2; i++)
{
System.out.print("Enter a name: ");
input.setName(keyboard.nextLine());
}
}
}
Class
Code:
public class writing
{
String name;
public void setName(String name)
{
this.name = name;
}
}
Yes, I want to display these names in order outside of for loop by using method. Is it possible? If there is any way to that, can you share?