Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Program {
- public static boolean containsBit(int mask, int el) {
- return ((mask & (1 << el)) != 0) ? true : false;
- }
- public static int insertBit(int mask, int el) {
- return (mask | (1 << el));
- }
- public static int eraseBit(int mask, int el) {
- return (mask & ~(1 << el));
- }
- public static int changeBit(int mask, int el) {
- return (mask ^ (1 << el));
- }
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int prisustviq = 0;
- while (true) {
- System.out.println("1. Print");
- System.out.println("2. Napishi prisustvie");
- System.out.println("3. Premahni prisustvie");
- System.out.println("4. Promeni prisustvie");
- System.out.println("5. to Exit");
- System.out.print("Enter option: ");
- String input = scan.nextLine();
- if (input.charAt(0) == '5') {
- break;
- } else if (input.charAt(0) == '1') {
- for (int i = 0; i < 32; i++) {
- System.out.print("Student #" + (i+1) + " : ");
- if (containsBit(prisustviq, i)) {
- System.out.println("TUK");
- } else {
- System.out.println("OTSUSTVA");
- }
- }
- } else if (input.charAt(0) == '2') {
- System.out.print("Enter student number: ");
- int num = Integer.parseInt(scan.nextLine());
- prisustviq = insertBit(prisustviq, num);
- } else if (input.charAt(0) == '3') {
- System.out.print("Enter student number: ");
- int num = Integer.parseInt(scan.nextLine());
- prisustviq = eraseBit(prisustviq, num);
- } else if (input.charAt(0) == '4') {
- System.out.print("Enter student number: ");
- int num = Integer.parseInt(scan.nextLine());
- prisustviq = changeBit(prisustviq, num);
- } else {
- System.out.println("Invalid option!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement