![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Hobbyist Programmer
Join Date: Aug 2005
Location: Hiding from... them...
Posts: 110
Rep Power: 3
![]() |
You probably want to put it in the if statement that checks if again == y.
|
|
|
|
|
|
#12 |
|
Expert Programmer
|
This is the code I used
import cs1.Keyboard;
import java.util.*;
public class HiLo
{
public static void main (String[] args)
{
int play = 1;
while(play > 0)
{
Random generator = new Random();
int answer = generator.nextInt(100)+1;
System.out.println("The computer is thinking of a number \nbetween 1 and 100. What is it?");
int escape = 0;
while(escape < 1)
{
int guess = Keyboard.readInt();
if(guess == answer)
{
System.out.println("That's it");
escape = 1;
}
else if(guess > answer)
{
System.out.println("Too High");
}
else if(guess < answer)
{
System.out.println("Too Low");
}
}
System.out.println("Would you like to play again (y/n)");
char again = Keyboard.readChar();
if(again == 'y')
{
System.out.print ("\033c");
play = 1;
}
else if(again == 'n')
{
play--;
}
}
}
}all it did was print a wierd symbol back where it says "The computer is thinking of a number between 1 and 100." |
|
|
|
|
|
#13 | |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
Quote:
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
|
|
#14 |
|
Expert Programmer
|
what will work on windows because that is what i'm using
|
|
|
|
|
|
#15 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
we can't compile anything that includes weird-ass files like cs1.keyboard unless we have that file. that's why all of the posts suck. nobody can run this thing. we're all just left here blowing in the wind. since it's an include, how about do a copy-and-paste and show the full source.
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
|
#16 |
|
Expert Programmer
|
|
|
|
|
|
|
#17 |
|
Newbie
Join Date: Oct 2005
Posts: 2
Rep Power: 0
![]() |
I didnt get too look at what crawford posted but i know that with the JVM you cannot make direct calls to the operating system. This means that the terminal clear code will not work. Also with the skipping lines, this leaves you at the bottom of the screen and most people do not want this. This leaves you really with only one way of doing it. Java has a class which allows you to call "Native classes" meaning classes written in different languages. This means you can write a class in C++ or C that clears the screen and make a call to it in java. Im working on this problem myself right now and am not exactly sure the way to go about it. Here is a link to a class that was already written by someone that will do it for u. http://mimosa.snu.ac.kr/~danke/etc/ClearScreen.zip
I also found another way of doing it using ANSI code but it requires you to alter your config.sys file. This would then make the code machine specific. If you want this code too just let me know. |
|
|
|
|
|
#18 |
|
Programming Guru
![]() |
Swimmfree200 , the JVM can write to the screen can't it? Good becase that's all the terminal clear screen code needs.
Thanks for the insight. [php] import java.io.*; public class RunCommand { public static void main(String args[]) { String s = null; Process clear; try { clear = Runtime.getRuntime().exec("cls"); BufferedReader stdOut = new BufferedReader(new InputStreamReader(clear.getInputStream())); while((s = stdOut.readLine()) != null) System.out.print(s); System.exit(0); } catch (IOException e) { try { clear = Runtime.getRuntime().exec("clear"); BufferedReader stdOut = new BufferedReader(new InputStreamReader(clear.getInputStream())); while((s = stdOut.readLine()) != null) System.out.print(s); System.exit(0); } catch(IOException d) { System.out.println("Get a real machine:"); d.printStackTrace(); System.exit(-1); } } } } [/php] That program clears the screen or throws an IOException on any windows or unix machine with the commands "cls" or "clear" respectively.
__________________
Last edited by tempest; Oct 9th, 2005 at 10:48 AM. |
|
|
|
|
|
#19 | |
|
Programmer
Join Date: Aug 2005
Location: 0x0010 * 0x0091 + 0x0004
Posts: 65
Rep Power: 3
![]() |
Quote:
__________________
#if 0 /* in case someone actually tries to compile this */ <Jim_McNeat> Is there like a way to put a compiler in "Just trust me on that one" mode? |
|
|
|
|
|
|
#20 |
|
Programming Guru
![]() |
There are two things that can go wrong, you can not have "clear" or not have "cls"... if you can't debug that without debugging information you've got issues as a programmer. Not to mention that this is supposed to be wrong in a terminal, so this code would be useless anywhere else...
__________________
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|