Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Program7 {
- private static int maxNumberStudents = 0;
- private static int actualNumberStudents = 0;
- private static String[] studentNames;
- public static void main(String[] args) {
- System.out.print("Please enter the maximum number of students:");
- Scanner input = new Scanner(System.in);
- int maxNumberStudents = input.nextInt();
- studentNames = new String[maxNumberStudents];
- enterStudentNames(studentNames);
- printStudentNames(studentNames);
- }
- public static void enterStudentNames(String[] studentNames) {
- Scanner nameInput = new Scanner(System.in);
- for (actualNumberStudents = 0; actualNumberStudents < maxNumberStudents; actualNumberStudents++) {
- System.out.print("First name (enter period . to quit:");
- String firstName = nameInput.next();
- if (firstName.equals(".")) {
- break;
- }
- System.out.println("Last name:");
- String lastName = nameInput.next();
- String fullStudentName = lastName + ", " + firstName;
- studentNames[actualNumberStudents] = fullStudentName;
- }
- }
- static void printStudentNames(String[] list) {
- for (int i = 0; i < actualNumberStudents; i++) {
- if (list[i].isEmpty() || list[i] == null) {
- break;
- }
- System.out.printf((i+1) + "," + list[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement