Advertisement
Guest User

Set program

a guest
Jan 22nd, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Program
  4. {
  5.  
  6.     public static void main(String[] args) {
  7.         System.out.println("Enter new set maximal size");
  8.         Scanner s = new Scanner(System.in);
  9.         int max = s.nextInt();
  10.         Set se = new Set(max);
  11.         int n = 1;
  12.         while(n!=0)
  13.         {
  14.             System.out.print("Current set is: ");
  15.             se.show();
  16.             System.out.println("Press 0 to exit program.");
  17.             System.out.println("Press 1 to add new number to set.");
  18.             System.out.println("Press 2 to remove exisiting number from set.");
  19.             n = s.nextInt();
  20.             if(n == 0)
  21.                 break; 
  22.             else if(n == 1)
  23.             {
  24.             System.out.println("Enter a number to add to set");
  25.             n = s.nextInt();
  26.             if(se.add(n))
  27.                 System.out.println("Adding " + n + " succeeded");
  28.             else
  29.                 System.out.println("Adding " + n + " failed");
  30.             }
  31.             else if(n == 2)
  32.             {
  33.                 System.out.println("Enter a number to remove from set");
  34.                 n = s.nextInt();
  35.                 if(se.remove(n))
  36.                     System.out.println("Removing " + n + " succeeded");
  37.                 else
  38.                     System.out.println("Removing " + n + " failed");
  39.             }
  40.         }
  41.     }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement