Example #1
0
  public static void main(String[] args) {
    System.out.println("Text Graphic");
    System.out.println("Made by Yakimov Denis for Hillel Java Courses.");
    System.out.println("Input number of lines and number of columns.");
    byte lenght = 0;
    byte height = 0;

    while (lenght == 0) {
      System.out.println("Input number of LINES");
      Scanner in = new Scanner(System.in);
      if (in.hasNextByte()) {
        lenght = in.nextByte();
      } else System.out.println("Error in data input, reinput number of lines!");
    }

    while (height == 0) {
      Scanner in = new Scanner(System.in);
      System.out.println("Input number of COLUMNS");
      if (in.hasNextByte()) {
        height = in.nextByte();
      } else System.out.println("Error in data input, reinput number of columns!");
    }

    Square(lenght, height);
    Letter(lenght);
    Checkmate(lenght, height);
  }
Example #2
0
 private static void processInput(Scanner in) {
   byte cases = in.nextByte();
   while (cases-- > 0) {
     String first = in.next();
     String second = in.next();
     if (compare(first, second) == true) {
       System.out.println("Yes");
     } else {
       System.out.println("No");
     }
   }
 }
  static void Venda() {
    // Declara variaveis
    byte poltrona = 0;
    String tipo = "";

    // Pega numero do assento
    do {
      System.out.println("Qual o numero da poltrona desejado de (1 a 24)?");
      while (!entrada.hasNextByte()) {
        System.out.println("Valor inválido! Qual o numero da poltrona desejado de (1 a 24)?");
        entrada.nextLine();
      }
      poltrona = entrada.nextByte();
      if (poltrona < 1 || poltrona > 24) {
        System.out.print("Valor inválido! ");
        entrada.nextLine();
      }
    } while (poltrona < 1 || poltrona > 24);

    // Pega tipo de assento
    do {
      System.out.println("Você deseja Janela (J) ou Corredor (C)?");
      tipo = entrada.next();
      if (!tipo.equalsIgnoreCase("C") && !tipo.equalsIgnoreCase("J")) {
        System.out.print("Valor inválido! ");
        entrada.next();
      }
    } while (!tipo.equalsIgnoreCase("C") && !tipo.equalsIgnoreCase("J"));

    // Verifica se assento esta ocupado
    if (assentoOcupado(poltrona, tipo)) {
      if (OnibusCheio()) {
        System.out.println("\n>< >< >< >< >< >< >< >< >< >< ");
        System.out.println(" Ônibus  *** L O T A D O ***");
        System.out.println(">< >< >< >< >< >< >< >< >< >< \n");
      } else {
        System.out.println(
            "\n >>> ERRO <<<  Poltrona OCUPADA \nTente outro Assento ou consulte o 'Mapa de Ocupação'\n");
      }
    } else {
      if (tipo.equalsIgnoreCase("C")) {
        C[poltrona - 1] = 1;
      } else {
        J[poltrona - 1] = 1;
      }
      System.out.println("\n=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=");
      System.out.println(
          " Venda efetuada com sucesso:  Poltrona "
              + poltrona
              + (tipo.equalsIgnoreCase("C") ? " Corredor" : " Janela"));
      System.out.println("=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=\n");
    }
  }
  public static void main(String args[]) {
    byte coins = 0;
    byte rep = 0;
    boolean win = true;
    boolean tie = true;
    byte play = 1;
    byte xp = -128;
    byte lvl = 1;
    short nXp = 0;
    byte showXp = 0; // TODO: use this to show more beautyfull xp
    byte rankXp = 0; // TODO: use this to show more beautyfull xp
    boolean showDialog = true;

    while (play != 0) {
      if (xp > -110 && showDialog) {
        System.out.println(
            "Congratulations, you lvl'ed up! You are lvl 1 now. \n You can now buy from the store!");
        showDialog = false;
        lvl++;
        xp = -128;
      }
      if (lvl > 1)
        System.out.println(
            "Do you want to play	R.P.S.? - Don't press 0. \n Do you want to use the store? - Press 2");
      else System.out.println("Do you want to play	R.P.S.? - Don't press 0.");
      if (play == 2)
        System.out.println(
            "Buy: Pattern giver(4GP) - Type -15 "
                + "\n Buy: Encrypted Win(24GP) - Type -25 \n Buy: 2 hour challenge(100GP) - Type -35 \n");
      Scanner sc = new Scanner(System.in);
      System.out.println(
          "-------------------- \n \n You have " + coins + " coins. \n Your xp: " + xp);
      play = sc.nextByte();
      if (
      /*win*/ play == 11) {
        System.out.println("You win! +3xp");
        coins += 5;
        xp += 3;
      } else if (
      /*tie*/ play == 22) {
        System.out.println("You tied..Respect.. +1xp");
        coins += 1;
        rep += 10;
        xp += 1;
      } else {
        System.out.println("You lost man...another time, another time..");
        if (coins != -128) coins--;
      }
    }
  }
  private void executeCommand(String command) {

    switch (command) {
      case "plus":
        mem.setCurrentCell((byte) (mem.getCurrentCell() + 1));
        break;

      case "minuse":
        mem.setCurrentCell((byte) (mem.getCurrentCell() - 1));
        break;

      case "write":
        StringBuilder sb = new StringBuilder(out);
        sb.append((char) mem.getCurrentCell());
        out = sb.toString();
        break;

      case "read":
        try {
          mem.setCurrentCell(scn.nextByte());
        } catch (InputMismatchException e) {
          System.out.println("Bad input!");
        }
        break;

      case "while_begin":
        if (mem.getCurrentCell() == 0) {
          whileWorking("while_end", "while_begin", 1);
        }
        break;

      case "while_end":
        if (mem.getCurrentCell() != 0) {
          whileWorking("while_begin", "while_end", -1);
        }
        break;

      case "right":
        mem.setCurrentMemoryIndex(mem.getCurrentMemoryIndex() + 1);

        break;

      case "left":
        mem.setCurrentMemoryIndex(mem.getCurrentMemoryIndex() - 1);

        break;
    }
  }
Example #6
0
  public static void main(String[] args) {
    System.out.println("\n intro dos números...");
    int a = leer.nextByte();
    int b = leer.nextByte();
    int may;
    if (a != b) {
      if (a > b) may = a;
      else may = b;
    } else may = a;

    int c = 2;
    if (esPrimo(a) && esPrimo(b)) System.out.println("\n sol_1: " + a * b);
    else {
      int mcm = minimo_c_m(a, b, may, c);
      System.out.println("\n sol_1: " + mcm);
    }
  }
Example #7
0
  public static byte leerByte() {
    byte numero = 0;
    boolean error;
    do {
      try {
        numero = teclado.nextByte();
        error = false;
      } catch (InputMismatchException e) {
        System.out.print("- Debe introducir un n�mero: ");

        error = true;
      } finally {
        teclado.nextLine();
      }
    } while (error);

    return numero;
  }
Example #8
0
 /** Read and return the next byte. */
 public static byte readByte() {
   return scanner.nextByte();
 }
Example #9
0
 public static byte numByte() {
   Scanner tec = new Scanner(System.in);
   byte n;
   n = tec.nextByte();
   return n;
 }
Example #10
0
  public static void main(String[] args) {

    System.out.print("Введіть ціле число (у 10-ній системі) що буде переведено - ");

    Scanner myScanner = new Scanner(System.in);

    int a =
        myScanner.nextInt(); // Число котре введене з клавіатури і буде переводитися в іншу систему
    System.out.println("Вкажіть (числом 1;2;3) в яку систему перевести число: ");
    System.out.println("1 - 2-во значну");
    System.out.println("2 - 8-и значну");
    System.out.println("3 - 16-ти значну");
    byte b = myScanner.nextByte();
    switch (b) {
      case 1:
        System.out.print("Бінарний код числа " + a + " є ");
        StringBuilder sb = new StringBuilder();
        do {
          sb.append(a % 2);
          a = a / 2;
        } while (a != 0);
        System.out.println(sb.reverse());
        break;

      case 2:
        System.out.print("Код у 8-ми значній системі числа " + a + " є ");
        StringBuilder c = new StringBuilder();
        do {
          c.append(a % 2);
          a = a / 8;
        } while (a != 0);
        System.out.println(c.reverse());
        break;

      case 3:
        System.out.print("Код у 16-ти значній системі числа " + a + " є ");
        System.out.println(Integer.toString(a, 16));
        /**
         * //a = 125; //int counter = 0;
         *
         * <p>int z = a / 16; // вираховуємо ціле число вираховуємо скільки 16-ток вміщається в
         * числі а int x = 16 * z; // ціле число із сумми 16-ток що вміщається у значенні а int v =
         * a - x; // залишок від віднімання. Різниця між а і х
         *
         * <p>if (v <= 9) System.out.println(v); else {
         *
         * <p>// abcdef(int );}
         *
         * <p>// public static void abcdef(int v){
         *
         * <p>if (v == 10) { v = 'A'; System.out.println((char) v); } else { if (v == 11) { v =
         * (char) 'B'; System.out.println((char) v); } else { if (v == 12) { v = (char) 'C';
         * System.out.println((char) v); } else { if (v == 13) { v = (char) 'D';
         * System.out.println((char) v); } else { if (v == 14) { v = (char) 'E';
         * System.out.println((char) v); } else { if (v == 15) { v = (char) 'F';
         * System.out.println((char) v); } } } } } } }
         *
         * <p>if (z > 16) { a = z; z = a / 16; // вираховуємо ціле число вираховуємо скільки 16-ток
         * вміщається в числі а x = 16 * b; // ціле число із сумми 16-ток що вміщається у значенні а
         * v = a - x; // залишок від віднімання (13) System.out.print(v); } break;
         */
    }
  }
Example #11
0
  public boolean load() {
    if (!file.exists()) return true;

    Scanner in;
    try {
      in = new Scanner(file);
    } catch (FileNotFoundException e) {
      pl.getLogger().severe("ipbans.dat appears to exist, but Scanner threw exception.");
      pl.getLogger().throwing(this.getClass().getName(), "load", e);
      return false;
    }

    Scanner tempScan;
    byte version = -1;
    List<String> buffer = new ArrayList<String>(10);
    while (in.hasNextLine()) {
      buffer.add(in.nextLine());
    }
    in.close();

    for (int i = 0; i < buffer.size(); i++) {
      String line = buffer.get(i);
      tempScan = new Scanner(line);
      {
        if (tempScan.hasNext()) {
          String identifier = tempScan.next();
          if (identifier.equals("VERSION:")) {
            if (tempScan.hasNextByte()) {
              version = tempScan.nextByte();
            } else {
              pl.getLogger().warning("Missing version number in " + file.getName());
              pl.getLogger().warning("Assuming " + IP_BANS_VERSION);
              version = IP_BANS_VERSION;
            }
          } else // IP listing
          {
            try {

              String ips = tempScan.next();

              tempScan.useDelimiter("\u00C4");
              String reason = tempScan.next();
              String info = tempScan.next();
              tempScan.reset();
              tempScan.skip("\u00C4");
              long endTime = tempScan.nextLong();
              String uuidStr = tempScan.next();
              String bannerUuidStr = tempScan.next();
              boolean isReq = tempScan.nextBoolean();
              long expireTime = -1;
              boolean aoe = false;
              if (isReq) {
                expireTime = tempScan.nextLong();
                aoe = tempScan.nextBoolean();
              }

              Scanner ipsScan = new Scanner(ips);
              ipsScan.useDelimiter(",");

              List<String> ipsList = new ArrayList<String>();

              while (ipsScan.hasNext()) ipsList.add(ipsScan.next());

              ipsScan.close();

              UUID banned = uuidStr.equals("null") ? null : UUID.fromString(uuidStr);
              UUID banner = bannerUuidStr.equals("null") ? null : UUID.fromString(bannerUuidStr);

              IpBan ipban =
                  new IpBan(ipsList, reason, info, endTime, banned, banner, isReq, expireTime, aoe);

              if (ipban.isOver()) {
                // it's over- dont add it back
                this.removeBan(ipban);
              } else if (ipban.isExpired()) {
                // its expired, fetch new ban if needed
                IpBan newBan = ipban.expire();
                if (newBan != null) {
                  this.addBan(newBan);
                }
                this.removeBan(ipban);
              } else {
                this.ipBans.add(ipban);
              }

            } catch (InputMismatchException ime) {
              pl.getLogger().severe("Input mismatch in " + file.getName() + ". Ban will be lost.");
              pl.getLogger().throwing(this.getClass().getName(), "load", ime);
              continue;
            } catch (NoSuchElementException nsee) {
              pl.getLogger().severe("Missing element in " + file.getName() + ". Ban will be lost.");
              pl.getLogger().throwing(this.getClass().getName(), "load", nsee);
              continue;
            }
          }
        } else {
          pl.getLogger().warning("Found unexpected empty line in " + file.getName());
        }
      }
      tempScan.close();
    }

    return true;
  }