For Example:
import java.util.Scanner; public class students { public static void main(String[] args){ Scanner sc = new Scanner(System.in); System.out.println("Enter Number of Students : "); int numOfStudents = Integer.parseInt(sc.nextLine()); //Create a string array to store the names of students String arrayOfNames[] = new String[numOfStudents]; for (int i = 0; i < arrayOfNames.length; i++) { System.out.println("Enter the name of student " + (i+1) + " : "); arrayOfNames[i] = sc.nextLine(); } // show student name one by one for (int i = 0; i < arrayOfNames.length; i++) { System.out.print("Student " + (i+1) + " : "); System.out.print(arrayOfNames[i] + "\n"); } } }