Advertisement
Guest User

hard

a guest
Aug 31st, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. public class Main {
  8. static Scanner sc = new Scanner(System.in);
  9. public static void main(String[] args) {
  10. //System.out.println("Please Select a Challenge");
  11.  
  12. challenge1easy();
  13. }
  14.  
  15. private static void challenge1easy() {
  16. List<Integer> x = new ArrayList<Integer>();
  17. for(int q=1;q<=10000;q++){
  18. x.add(q);
  19. System.out.print(q+ " ");
  20.  
  21. }
  22. System.out.println("Finished Generating Array List");
  23. int guess;
  24. guess=x.get(x.size()-1);
  25. guess=guess/2;
  26. boolean correct = false;
  27. String a = "";
  28. System.out.println("First Guess is: "+ guess);
  29. while(correct==false){
  30. if(x.size()==1){
  31. System.out.println(x.get(0)+" Winner");
  32. System.exit(1);
  33. }
  34. System.out.println("Higher,Lower,Correct?");
  35. a = sc.nextLine();
  36. if (a.equals("Higher")){
  37. for(int h=0;h<x.size();h++){
  38. if(x.get(h)==guess){
  39. x= x.subList(h,x.size());
  40.  
  41. }
  42.  
  43. }
  44. for(int h=0;h<x.size();h++){
  45. System.out.print(x.get(h)+" ");
  46. }
  47. }else if(a.equals("Lower")){
  48. for(int h=0;h<x.size();h++){
  49. if(x.get(h)==guess){
  50. x=x.subList(0,h);
  51. }
  52. }
  53. for(int h=0;h<x.size();h++){
  54. System.out.print(x.get(h)+" ");
  55. }
  56. }else if(a.equals("Correct")){
  57. System.out.println("WINNER");
  58. System.exit(1);
  59. }
  60. else{
  61. System.exit(12);
  62. }
  63. guess=(x.size()/2);
  64. guess=x.get(guess);
  65.  
  66. System.out.println("Our Guess is: "+guess);
  67.  
  68. }
  69.  
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement