SHARE
TWEET

Untitled

a guest Nov 16th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class Program7 {
  4.     private static int maxNumberStudents = 0;
  5.     private static int actualNumberStudents = 0;
  6.     private static String[] studentNames;
  7.  
  8.     public static void main(String[] args) {
  9.         System.out.print("Please enter the maximum number of students:");
  10.         Scanner input = new Scanner(System.in);
  11.         int maxNumberStudents = input.nextInt();
  12.         studentNames = new String[maxNumberStudents];
  13.         enterStudentNames(studentNames);
  14.         printStudentNames(studentNames);
  15.  
  16.     }
  17.  
  18.     public static void enterStudentNames(String[] studentNames) {
  19.         Scanner nameInput = new Scanner(System.in);
  20.  
  21.         for (actualNumberStudents = 0; actualNumberStudents < maxNumberStudents; actualNumberStudents++) {
  22.             System.out.print("First name (enter period . to quit:");
  23.             String firstName = nameInput.next();
  24.             if (firstName.equals(".")) {
  25.                 break;
  26.             }
  27.             System.out.println("Last name:");
  28.             String lastName = nameInput.next();
  29.             String fullStudentName = lastName + ", " + firstName;
  30.             studentNames[actualNumberStudents] = fullStudentName;
  31.         }
  32.     }
  33.  
  34.     static void printStudentNames(String[] list) {
  35.         for (int i = 0; i < actualNumberStudents; i++) {
  36.             if (list[i].isEmpty() || list[i] == null) {
  37.                 break;
  38.             }
  39.             System.out.printf((i+1) + "," + list[i]);
  40.  
  41.         }
  42.     }
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top