Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class Main {
- static Scanner sc = new Scanner(System.in);
- public static void main(String[] args) {
- //System.out.println("Please Select a Challenge");
- challenge1easy();
- }
- private static void challenge1easy() {
- List<Integer> x = new ArrayList<Integer>();
- for(int q=1;q<=10000;q++){
- x.add(q);
- System.out.print(q+ " ");
- }
- System.out.println("Finished Generating Array List");
- int guess;
- guess=x.get(x.size()-1);
- guess=guess/2;
- boolean correct = false;
- String a = "";
- System.out.println("First Guess is: "+ guess);
- while(correct==false){
- if(x.size()==1){
- System.out.println(x.get(0)+" Winner");
- System.exit(1);
- }
- System.out.println("Higher,Lower,Correct?");
- a = sc.nextLine();
- if (a.equals("Higher")){
- for(int h=0;h<x.size();h++){
- if(x.get(h)==guess){
- x= x.subList(h,x.size());
- }
- }
- for(int h=0;h<x.size();h++){
- System.out.print(x.get(h)+" ");
- }
- }else if(a.equals("Lower")){
- for(int h=0;h<x.size();h++){
- if(x.get(h)==guess){
- x=x.subList(0,h);
- }
- }
- for(int h=0;h<x.size();h++){
- System.out.print(x.get(h)+" ");
- }
- }else if(a.equals("Correct")){
- System.out.println("WINNER");
- System.exit(1);
- }
- else{
- System.exit(12);
- }
- guess=(x.size()/2);
- guess=x.get(guess);
- System.out.println("Our Guess is: "+guess);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement