Returning focus to the command line?

I am trying to write a text based card game but I am stuck again. When I run this code after I type "help" to view the key words the program terminates. How would I go about retuning focus to the command line instead of terminating the program.
import java.util.*;
import java.io.*;
public class BlackJack {
public static String help = "\tKey Words\n--------------------\nhelp = Help\ndeal = New Game\nhit = Get Another Card\ncall = Dealer shows cards";
public static void main(String[] args) {
System.out.println("Welcome to Black Jack!\nPlease enter a value.\nEnter \"help\" for help.");
String input = "";
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader buffer = new BufferedReader(isr);
try {
input = buffer.readLine();
buffer.close();
if(input.equals("help")) {
System.out.println(help);
else {
System.out.println("Incorrect please try again!");
catch(IOException e) {
System.out.println("Incorrect value please try again!");
}Edited by: Aj_Green on Aug 7, 2008 11:25 AM

I have created a method for getInput() however; when I type "help" the while loop infinately prints my else string. Here is the code. If I type "quit" into the command line the program terminates as it should.
import java.util.*;
import java.io.*;
public class BlackJack {
     public static String help = "\tKey Words\n--------------------\nhelp = Help\ndeal = New Game\nhit = Get Another Card\ncall = Dealer shows cards";
     public static String getInput() {
          InputStreamReader isr = new InputStreamReader(System.in);
           BufferedReader buffer = new BufferedReader(isr);
          String input = "";
          try {
          input = buffer.readLine();
          buffer.close();
          return input;     
          catch(IOException e) {
          System.out.println("An input error has occured!");
          return input;
     public static void main(String[] args) {
          System.out.println("Welcome to Black Jack!\nPlease enter a value.\nEnter \"help\" for help.");
          boolean gameOver = false;
          while(!gameOver) {
          String ans = getInput();
          if("quit".equals(ans)) {
          gameOver = true;
          else if("help".equals(ans)) {
          System.out.println(help);
          else {
          System.out.println("Incorrect please try again!");
}Edited by: Aj_Green on Aug 7, 2008 12:38 PM

Similar Messages

  • How do I execute a returned sql string from a function on the command line?

    Hi,
    I have written a pl/sql function that will dynamically create a sql select statement. I need to be able to execute this statement from the command line. e.g from sqlplus
    Say my function is called "sql_create" and it returns "select * from customer"
    How do I execute the returned value from the command line?" Is it possible?
    SQL> select sql_create from dual;
    SQL_CREATE
    select * from customer
    SQL>
    So I try:
    SQL> exec execute immediate 'select sql_create from dual';
    SQL>
    I don't get an error but I don't get the result set either.
    Is there a command I can use instead of execute immediate?
    thanks,
    Susan
    Edited by: Susan123456 on Jul 2, 2009 1:21 AM

    depends on the frontend. Most frontends (like Java and .Net) know how to handle REF CURSORS. Instead of returing a "string" which represents a query, return a ref cursor
    SQL> ed
    Wrote file afiedt.buf
      1  create function sql_q return sys_refcursor
      2  is
      3     rc sys_refcursor;
      4  begin
      5     open rc for select * from emp;
      6     return rc;
      7* end;
    SQL> /
    Function created.
    SQL> var r refcursor
    SQL>
    SQL> exec :r := sql_q
    PL/SQL procedure successfully completed.
    SQL> print r
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-80        900                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-81       1700        300         30
          7521 WARD       SALESMAN        7698 22-FEB-81       1350        500         30
          7566 JONES      MANAGER         7839 02-APR-81       3075                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1350       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2950                    30
          7782 CLARK      MANAGER         7934 09-JUN-81       2551                    10
          7788 SCOTT      ANALYST         7566 19-APR-87       3100                    20
          7839 KING       PRESIDENT            17-NOV-81       5100                    10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1600          0         30
          7876 ADAMS      CLERK           7788 23-MAY-87       1200                    20
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7900 JAMES      CLERK           7698 03-DEC-81       1050                    30
          7902 FORD       ANALYST         7566 03-DEC-81       3100                    20
          7934 MILLER     CLERK           7782 23-JAN-82       1400                    10

  • Question about reading a string or integer at the command line.

    Now I know java doesn't have something like scanf/readln buillt into it, but I was wondering what's the easiest, and what's the most robust way to add this functionality? (This may require two separate answers, sorry).
    The reason I ask is because I've been learning java via self study for the SCJA, and last night was the first time I ever attempted to do this and it was just hellish. I was trying to make a simple guessing game at the command line, I didn't realize there wasn't a command read keyboard input.
    After fighting with the code for an hour trying to figure it out, I finally got it to read the line via a buffered reader and InputStreamReader(System.in), and ran a try block that threw an exception. Then I just used parseInt to get the integer value for the guess.
    Another question: To take command line input, do you have to throw an exception? And is there an easier way to make this work? It seems awfully complicated to take user input without a jframe and calling swing.
    Edited by: JGannon on Nov 1, 2007 2:09 PM

    1. Does scanner still work in JDK1.6?Try it and see. (Hint: the 1.6 documentation for the class says "Since: 1.5")
    If you get behaviour that doesn't fit with what you expect it to do, post your code and a description of our expectations.
    2. Are scanner and console essentially the same thing?No.
    Scanner is a class that provides methods to break up its input into pieces and return them as strings and primitive values. The input can be a variety of things: File InputStream, String etc (see the Scanner constructor documentation). The emphasis is on the scanning methods, not the input source.
    Console, on the other hand, is for working with ... the console. What the "console" is (and whether it is anything) depends on the JVM. It doesn't provide a lot of functionality (although the "masked" password input can't be obtained easily any other way). In terms of your task it will provide a reader associated with the console from which you can create a BufferedReader and proceed as you are at the moment. The emphasis with this class is the particular input source (and output destination), not the scanning.
    http://java.sun.com/javase/6/docs/api/java/util/Scanner.html
    http://java.sun.com/javase/6/docs/api/java/io/Console.html

  • SQL 2012 SSIS package runs from the command line (dtexec.exe) and completes right away ...

    Hi
    I’m upgrading our SSIS packages from SQL 2005 to SQL 2012 .
    Everything is working fine in Visual Studio, but when I’m submitting dtexec.exe it’s finishing right away in the command line (the actual execution takes long time). 
    It looks to me that as the return code doesn’t pass properly.
    As I have depending tasks how I can make sure all jobs will be executed in the proper order.
    (We never had this issue in SQL 2005)
    C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn>dtexec.exe /ISSERVER "\"\SSISDB\Direct_Prod\Direct_SSIS_Package
    \DD_Load_Customer.dtsx\"" /SERVER TORSQLSIS01 /ENVREFERENCE 2
    Microsoft (R) SQL Server Execute Package Utility
    Version 11.0.2100.60 for 32-bit
    Copyright (C) Microsoft Corporation. All rights reserved.
    Started:  10:21:55 AM
    Execution ID: 21138.
    To view the details for the execution, right-click on the Integration Services Catalog, and open the [All Executions] report
    Started:  10:21:55 AM
    Finished: 10:21:56 AM
    Elapsed:  0.766 seconds

    As per MSDN /ENVREFERENCE argument is used only by SQL Server Agent
    see
    https://msdn.microsoft.com/en-us/library/hh231187.aspx
    below part is what it says
    /Env[Reference] environment reference ID
    (Optional). Specifies the environment reference (ID) that is used by the package execution, for a package that is deployed to the Integration Services server. The parameters configured to bind
    to variables will use the values of the variables that are contained in the environment.
    You use /Env[Reference] option together with the /ISServer and the /Server options.
    This parameter is used by SQL Server Agent.
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Merge/concatenate animation codec movie files in the command line/shell

    We know how to join 2 mp4/h264 movies together in the command line/shell via MP4Box.
    We have not been able to find a similar tool for joining to Quicktime Animation codec movie together via command line/shell.
    Anyone know how to do that of have suggestions?
    thanks,
    paul

    Hi,
    I'm also having trouble with this same issue. I've been trying to change the Quicktime Default Setting to 10-bit uncompressed (btw codec works fine out directly out of QT and other apps), or to use the command line to do quick renders of tiff frame sequences to QT 10-bit. I think its a problem with my syntax on the command line. As per the manual I set up a fileout in a script with 10-bit as the codec, opened the script in Textedit and followed the instructions on p393, and dropped it into the include/startup directory. Below is a copy of the Textedit view of the script output settings. Also, If I want to use these settings the command line what should I change? The quotation marks, commas etc?
    "QuickTime", "Shake 3 QT 1", "Apple FCP Uncompressed 10-bit 4:2:2",
    0, "100W@c6000WDcsuHpoe10pFnKA6W230PPMMRH#0LgfI5ALV1EaKGn3DG3214QaPb03SeOBPg00K1bY AESIIW0KAbabF7YWOQan8401v6QvQehFnRYIBt9be1B4AEjYA6ci8YmM#IKXCg5aRMZC2MXBM0Ani04w HAJLmBrQ97MtegeEEO9d5oBoxCgv7GNhEOvai8INwFwb2roIf91bvbr040HAK4IYCW0",
    0, 44100, 16);
    I get the same message returned in Terminal:
    error: - NRiCompressor - corrupted input data (length)
    The QuickTime codec specified in the global default could not be selected. The system default codec will be selected.
    So it renders to Animation. Something else I found was that the example on p393 in the manual is for 10-bit uncompressed - so I tried copying it right off the page, into Textedit, and into the include/startup dir - still no joy.
    Can anyone shed any light on the matter?
    D.
    G5 Quad 2.5   Mac OS X (10.4.8)  

  • Counting arguments in the command line

    I need to write a snip of code that will check the command line to make sure there are 5, no more or less, arguments. If not I have to return an error message. Anyone have any ideas?
    Stephen

    The command line args will be in a String[] passed to main(). Arrays have a length field that tells you how many elements they have.
    http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html

  • Pass the command line argument (argc and argv) to a LabVIEW built shared library.

    Hello,
    I have successully use this trick to build a LabVIEW application that runs on Linux without X Display.
    http://digital.ni.com/public.nsf/allkb/5D6EC36DCF43343786257449006919E6
    I'd like to know if it's possible to pass the command line arguments ( ./TEST A B C D) directly into the shared library without having to pass the arguments using a array of strings which would require to write code using DSNewHandle, DSSetHandleSize, extract the arguments and ..... (I'm not proficient in C, but if I don't have a choice I will do it and improve my C skills).
    int main(int argc, char *argv[])
            Test(argc, argv);
            return 0;
    Thanks,
    Michel
    Solved!
    Go to Solution.

    Well, you can always flatten it back into a space separated single string and pass it like that. Basically reverse what the OS does when it calls your main function with the command line parameters. And while the first element in the array is always the program name itself you can just skip that here, but then format all the rest into a single string.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • RH9 - Any idea why generating printable output from the Command Line doesn't include images?

    I have a batch file that creates a printable output of our main documentation broken up into 36 separate documents, 1 per chapter. Each chapter is a separate layout. I realize that RH has its own Batch building process, but the reason for me doing it through the command line via a batch file (.bat) is that RH keeps taking focus from my mouse and it makes it difficult to do any other computer work while the RH project generates the printable output for those chapters.
    Anyway, RH's Batch build works fine.
    But the command line for printable output does not include any of my images in the printable output. I don't know why. The document generates with all the topics fine, but the images are missing. No placeholder box in the resulting Word doc, they just simply weren't included. Has anyone else seen this? Any way to fix it?

    All,
    I thought it may be related to spaces in the path in which the script was called from. I tried having the ODBC command script in another directory but the same thing happens. It will give me the "CONFIGSYSDSN: Unable to create a data source for the 'Oracle in OraClient10g_home1' driver: Could not load the setup or translator library with error code -2147467259". As soon as the script is done running I can manually double click the script and it adds the DSN fine.
    Thanks,
    Clif Bridegum

  • Running a jar from the command line

    I am trying to run a Jar from the command line. I have a number of classes in a package called "trainnn".
    I put all the classes into a jar
    jar cvf name.jar trainnn\*.classI then creat a file called mainClass.txt with the line (with a blank return line after it, where QueryMatch has the main). This file was placed in the same directory as the package and the jar file
    Main-Class: QueryMatch
    then
    jar cmf mainClass.txt network.jar G:/TrainNN/src/trainnn/QueryMatch.classthis worked fine.....but it is from here I have problems when I try run the jar
    java -jar network.jarbut get this error.
    Exception in thread "main" java.lang.NoClassDefFoundError: QueryMatch
    I cant figure out this error, I have tried specifying the exact path in the mainClass.txt file but that didnt work.
    Any ideas
    Thanks in advance.

    Hi,
    To start a java app in the command line with "java -jar yourJarFile.jar", the jar needs to have a mainfest file "MANIFEST.MF" in a folder called "META-INF". The manifest file would have to contain the name of your starting class, e.g. it could look like thisManifest-Version: 1.0
    Main-Class: com.yourCompany.yourProject.YourClass Hope that helps. Cheers, HJK

  • Ffmpeg wrapper that behaves like the command line

    I have ffmpeg compiling now and can package up a swc using the wrapper code from  www.rainbowcreatures.com/product_flashywrappers.php
    It all works etc but doesnt quite do what I need, instead of passing frames I need to pass it a complete h264 stream as bytearray and get it to output either rawvideo frames or an flv.
    Would it be possible to knock up a wrapper that basically gives command line style access, using pipe access in/out etc.  I have 0 c knowledge but woudlnt it be easier than writing wrapper functions for each specific function we need?

    Hi, I'm actually the author of FlashyWrappers
    I was trying to do just that but then it started to appear too hard to understand all that source in ffmpeg.c and ffmpeg_opt.c instead of starting from the basic wrapper, so I abandoned that approach. Another reason was I wanted something "async" so that the Flash doesn't freeze - by just rewriting the command line tool I figured it would launch and return only when its done, freezing everything else in the meantime. A solution of course would be to launch it on another worker, but I wanted to also show progress %, since transcoding/encoding takes quite some time.
    So eventually I had faster success with the custom wrapper. THe fastest soution for you would also be a custom wrapper I might derive from my original wrapper. The biggest issue I've seen at the time, apart from not understanding ffmpeg, was to rewrite input/output of their tool to "normal" memory as ffmpeg had special approaches to achieve that, like writing your own protocol which I had to grasp yet.
    Looking back at it, I think I might be  able to rewrite the command line tool since I've learned  how to replace file input/output by memory in my own wrapper. The async / % issue would still be present of course, but in time that might be tweaked. My current priorities are finishing FlashyWrappers 2.0 and also finishing a product derived from that. But I might take on porting ffmpeg command line after that, its of course appealing to have universal solution for ffmpeg in web Flash.

  • Can I create a new folder using the command line interface

    Hi.
    Is there a way to create a new folder in an existing business area, from the command-line?
    We have an application that provides an interface for the user to create a table and load flat file data into the table. After loading the data, the user will verify the loaded data using discoverer. If there is a command line interface to create a new folder, then the script that created the table can also call the discoverer command line to create a new folder for the new table. Is this possible?
    Thanks

    Hi,
    I think I am having a similar question here. I am using Oracle 10g on Windows xp.
    I logged in to Oracle from command prompt. I used command “create directory myFunDir as 'd:/funDir';”. Oracle returns: “Directory created”. But I couldn’t find the directory “myFunDir”! Where is it?
    Thanks.
    Newbie.

  • Could not view data in the Em while in the command line query works

    Hi, all,
    I have met with this problem for several times.
    I have an Oracle 10.0.2.0 running on Redhat linux E3.
    After I insert or just input some data in a table. I could see the new data in the command line.
    SQL> select * from tablename;
    But I could not see the new data in the EM. If I export the table to, say, MS Access, the new data doesn't show. The data is there, but I have to wait for some time. (several mins to hours)
    Do you have any idea of it??
    Thank you very much!
    Qian

    Thank you for your reply.
    Why sometimes it doesn't show in other sessions, but sometimes it shows?
    Any way, I will perform commit to see....
    Qian
    Message was edited by:
    QianChen

  • How can I open a PDF file and enter a word in the Find field from the command line?

    Hi,
    I want to use a PDF file as the help file of another program.
    I have found somewhere an incomplete description of the command line parameters of Acrobat Reader.
    It described how to open a file and jump to its given page.
    I have written the following batch file based on that.
    rem Open pdf (prm1) with Acrobat reader at given page (prm2)
    "%adobe_rdr%\AcroRd32.exe" /N "zoom=73&page=%2=OpenActions" %1
    The following batch file opens the search dialog:
    rem Open pdf (prm1) with Acrobat reader
    rem and search for something (prm2)
    "%adobe_rdr%\AcroRd32.exe" /N "zoom=73&navpanes=1=OpenActions&search=%2" %1
    I need the simple find field instead of the complicated search window.
    Regards
                   Ferenc

    Not possible.

  • I am trying to set an open DNS using the MacAir. But when I tried to flush the existing one at utilities/terminal, it will not work.  I am using Yosemite.  May I know what should be the command line so that I can shift to an open DNS?  Thanks

    I am trying to set an open DNS using the MacAir. But when I tried to flush the existing one at utilities/terminal, it will not work.  I am using Yosemite.  May I know what should be the command line so that I can shift to an open DNS?  Thanks

    >SystemPreferences>Network>DNS

  • Error while running the Discoverer report from the command line.

    Hi All,
    I've to run a discoverer report from command line and export the results in xls/html on to my local machine. This report I've to run it as batch and scheduled it.
    I have a parameterized worksheet and this has to be run from command line specifying the parameter value I wanted to run the report for. I do not get any results. Here is the command line I am using.
    dis51usr /connect user/password@database /opendb "TIMS-PCJ status Report" /sheet "TIMS observation status report (based on performed date)" /parameter "Test Number" '40351' /parameter "From Date" '05-MAY-2008' /parameter "To Date" '06-MAY-2008' /export HTML "C:\DISCOVERER_REPORT_SCHEDULING\DIS_OUTPUT\PCJStOutputinHTML123"
    I even added the TO_DATE conversion for the parameters and also gave the format of the date as 'DD_MON_YYYY'.
    Discoverer Desktop opened up, logged in and gets terminated saying 'Oracle Discoverer Desktop has encountered a problem and need to close. We are sorry for the inconvenience.'
    Please anyone reply me.
    Regards & Thanks,
    P. Gayathri Devi

    Hi Gayathri,
    Try changing your parameter names to be a single word. (Change "Test Number" to Test_Number).
    Does the report run fine when run through Desktop for the same parameter values? Which version of Discoverer are you using?
    Thanks.

Maybe you are looking for

  • Problem with TimeCapsule after upgrading to new mac...

    hi, I bought a new UniBody MacBook just before Xmas, and turned off TimeMachine during the upgrade from my PowerPC G4. Since then, until now, I stupidly forgot to turn it back on. Now I did remember, it doesn't work! It tells me it it failed with the

  • ACE Issue

    Hello Experts, As per my requirement I have to restrict Settlements using ACE control. For the above purpose I have added Billing has new super object and linked it with Billing (CRM object) , I have created ACL,GRP and UTC tables along with custom c

  • Rename the table !!

    User is asking to rename the table ! Is there any syntax out there to rename the table without dropping and recrreating whole table. From P

  • Synchronise all Apple devices and retrieve data?

    Hi, I have just bought a new Apple Pro, having moved from a Windows system.  I have an iPad but don't know how to synchronise the two devices.  I also had an iTunes account on my old computer which the Mac is showing as empty! Can I retrieve my conte

  • How to use NIDAQmx to measure voltage, resistance and thermocoup​les

    I'm new to using NIDAQmx. I was looking for examples to measure multiple functions like voltage, resistance and thermocouple in the continuous mode at the same time. ben