Advertisement
Guest User

TD6 question 5

a guest
Oct 23rd, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6.  
  7. package finder;
  8. import java.util.Scanner;
  9. /**
  10. *
  11. * @author Quentin
  12. */
  13. public class Finder {
  14.  
  15. /**
  16. * @param args the command line arguments
  17. */
  18. public static void main(String[] args) {
  19. System.out.println("pensez à un nombre entre 1 et 100");
  20. Scanner sc = new Scanner(System.in);
  21. int bornesup = 100;
  22. int borneinf = 0;
  23. System.out.println("Est-ce " + Integer.toString((bornesup + borneinf)/2) + "?");
  24. int rep = sc.nextInt();
  25. while (rep != 0){
  26. if (rep == 1){
  27. borneinf = (bornesup + borneinf)/2;
  28. }
  29. else{
  30. bornesup = (bornesup + borneinf)/2;
  31. }
  32. System.out.println("Est-ce " + Integer.toString((bornesup + borneinf)/2) + "?");
  33. rep = sc.nextInt();
  34. }
  35. }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement