Advertisement
glee20

marriageArrayList

Nov 27th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3. public class arrayList
  4. {
  5.     public static void main (String args []){
  6.         ArrayList <Boolean> marriage = new ArrayList <Boolean>(5);
  7.         ArrayList <String> name = new ArrayList <String>(5);
  8.         Scanner in = new Scanner(System.in);
  9.         int x = 0;
  10.        
  11.         while (x<5) {
  12.             System.out.println("Enter your name.");
  13.             name.add(in.next());
  14.             System.out.println("If you are married, enter Y. Else, enter N.");
  15.             String status = in.next();
  16.             if (status.equals("Y")) {
  17.                 marriage.add(true);
  18.             }
  19.             else if (status.equals("N")) {
  20.                 marriage.add(false);
  21.             }
  22.             else {
  23.                 System.out.println("Error.");
  24.                 name.remove(x);
  25.                 x=x-1;
  26.             }
  27.             x++;
  28.         }
  29.        
  30.         System.out.println("List of People who are married");
  31.         for (x=0; x<name.size(); x++) {
  32.             if (marriage.get(x) == true) {
  33.                 System.out.println(name.get(x));
  34.             }
  35.         }
  36.        
  37.         System.out.println("List of People who are not married");        
  38.         for (x=0; x<name.size(); x++) {
  39.             if (marriage.get(x) == false) {
  40.                 System.out.println(name.get(x));
  41.             }
  42.         }
  43.     }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement