Results 1 to 4 of 4

Thread: Eclipse Console

  1. #1
    Candace is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Eclipse Console

    Hello,

    I have done some minute programming in the past, but it was mostly with C++ and .Net; I am trying to make a simple program that will allow the user to guess the number the computer has generated. I have the program working, but my issue lies with Eclipse. When I run the program it pops up the Console view but will not let me type a number (or anything for that matter) to enter my guess. I have looked into Scanner objects and do not feel they are correct for this since I am not trying to store the user input. I just need it to compare the variable guess to the answer variable, but again it will not let me type anything. I have a blinking cursor in the console, and the code does compile. I am kinda going crazy over this, so here is the code that I have.

    / Just a program that guesses a number.
    Java Code:
    // Imports Random Number Generator
    import java.util.Random;
    
    
    public class Main 
    {
    	
    	
    	 public static void main(String[] args) {
    	 
    		 // Declare Variables
    		 int answer, numOfGuess, guess = 0;
    		 
    		// Initialize Random Generator
    		 Random generator = new Random();
    		 // Initialize guess count to zero
    		 numOfGuess = 0;
    		 
    		
    		 
    		 do{
    			 // Gives range of number generator
    			 answer = generator.nextInt() * 100;
    			 System.out.println("Guess a number between 1 - 100 or press 0 to quit: ");
    			 do {
    				 if (guess == 0){
    					 System.exit(0);
    				 }
    				 if (guess > answer) {
    				  System.out.println("Guess is too high");
    				 }
    				 if (guess < answer) {
    					 System.out.println("Guess is too low");
    				 }
    				 if (guess == answer) {
    					 System.out.println("You got it right! Way to go!");
    				 } }
    		 while (guess !=0);
    			 }
    		 while (answer == answer);
    	 
    			 
    	 }
    }
    Last edited by JosAH; 05-24-2012 at 09:22 AM. Reason: added [code] ... [/code] tags

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,004
    Blog Entries
    7
    Rep Power
    20

    Default Re: Eclipse Console

    Eclipse uses its own console (it's near the bottom of the screen if you didn't change its layout); click on it to select it and type away ...

    kind regards,

    Jos

    edit: I only noticed just now: your program exits immediately (guess == 0 to start with)

    edit2: your generated answer isn't an answer in the range [1 ... 100]; you should've added code tags for readability reasons.

    edit3: I added those tags for you.
    Last edited by JosAH; 05-24-2012 at 09:23 AM.
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    Candace is offline Member
    Join Date
    May 2012
    Posts
    2
    Rep Power
    0

    Default Re: Eclipse Console

    I have done that. I saw it pop up the Console view when I ran the program, but it isn't typing anything. Letters, numbers, nothing. Hence my confusion. Is there something wrong with my code?

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,004
    Blog Entries
    7
    Rep Power
    20

    Default Re: Eclipse Console

    Quote Originally Posted by Candace View Post
    I have done that. I saw it pop up the Console view when I ran the program, but it isn't typing anything. Letters, numbers, nothing. Hence my confusion. Is there something wrong with my code?
    Read my previous reply (especially the 'edit1' paragraph).

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 6
    Last Post: 01-30-2014, 01:56 PM
  2. Help with Console
    By thiagohe in forum Advanced Java
    Replies: 7
    Last Post: 08-01-2011, 01:30 PM
  3. Eclipse (Clear Console Command)
    By rizowski in forum New To Java
    Replies: 2
    Last Post: 01-15-2011, 12:02 AM
  4. In-game console
    By Mr.Beans in forum New To Java
    Replies: 5
    Last Post: 08-17-2009, 10:22 PM
  5. Replies: 1
    Last Post: 12-13-2008, 01:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •