Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package zgadywanka;
- /**
- *
- * @author Emperor
- */
- public class Zgadywanka {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- int ileElementow = 1000;
- System.out.println("Nastepuje zwolnienie blokady. Losujemy od 1-" + ileElementow);
- int wylosowana = (int) (Math.random() * ileElementow) + 1;
- System.out.println("System wylosowal: " + wylosowana);
- int zgaduje = ileElementow / 2;
- int pierwszy = 1;
- int ostatni = ileElementow;
- int temp;
- int licznik = 1;
- System.out.println("\tPIE:" + pierwszy + ", OST:" + ostatni);
- while (true) {
- System.out.print((licznik++) + " Zgaduje ze to: " + zgaduje);
- if (zgaduje == wylosowana) {
- break;
- } else if (zgaduje < wylosowana) {
- System.out.println(" < " + wylosowana);
- temp = zgaduje;
- zgaduje = (ostatni - zgaduje + 1) / 2 + zgaduje;
- pierwszy = temp;
- } else {
- System.out.println(" > " + wylosowana);
- temp = zgaduje;
- zgaduje = (zgaduje - pierwszy + 1) / 2 + pierwszy;
- ostatni = temp;
- }
- System.out.println("\tPIE:" + pierwszy + ", OST:" + ostatni);
- }
- System.out.println(" = " + wylosowana);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement