Results 1 to 4 of 4
Thread: Eclipse Console
- 05-24-2012, 09:15 AM #1
Member
- Join Date
- May 2012
- Posts
- 2
- Rep Power
- 0
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
- 05-24-2012, 09:18 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,404
- Blog Entries
- 7
- Rep Power
- 17
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.
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 05-24-2012, 09:19 AM #3
Member
- Join Date
- May 2012
- Posts
- 2
- Rep Power
- 0
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?
- 05-24-2012, 09:24 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,404
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Application runs in Eclipse console. How to make it a stand alone app?
By tmboredi in forum New To JavaReplies: 4Last Post: 01-12-2012, 05:25 PM -
Help with Console
By thiagohe in forum Advanced JavaReplies: 7Last Post: 08-01-2011, 01:30 PM -
Eclipse (Clear Console Command)
By rizowski in forum New To JavaReplies: 2Last Post: 01-15-2011, 12:02 AM -
In-game console
By Mr.Beans in forum New To JavaReplies: 5Last Post: 08-17-2009, 10:22 PM -
Link an external compiler to the eclipse environment throw the console in eclispe
By adolf111 in forum EclipseReplies: 1Last Post: 12-13-2008, 01:24 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks