StringTokenizer to read in 4 variables from the command point

Hi,
I need to set up the Java StringTokenizer to read in 4 variables
from a command prompt. It should be in the following format:
X variable1 variable2 variable3where
(is the command prompt)X (is either +, -, *, /, c, or e)
variable1 variable2 and variable3 are integers.
I would appreciate any answers that would help me find the way!
Thanks in advance.

Thank you for the code snippet, but the program does not function that way. Ie, it does not accept
arguments when the program is first run, only after the program has excecuted.
The program is to enter a simple command prompt, and await instructions in the form X int1 int2 int3
where X can be c (convert the number int3 from number base int1 to number base int2), e (exit the
program), +,-,/,* (add, subtract, divide or mutilply int2 to/by int3 in number base int1). Here is an example
of the what the program execution should look like:
c:\programming\java nbc
> + 10 23 45 // Add 23+45 in base10
68 // Write the answer on a new line and prompt
- 16 5A 2C // Subtract 5A-2C in base 162E // Write the answer on a new line and prompt
c 15 7 2E // Convert 2E in base 15 to base 762
e // End of programc:\programming\
My problem is, I do not know how to convert the first token to a variable that can be used to carry out one of
the above mentioned procedures. For example, the first token taken from the command c 15 7 2E is "c".
As I understand it, "c" is simply a string, and this cannot be used in logical procedures such as:
int procedure = 0;
if(operator == "c")
     procedure = 0;  //then use this variable
}else
if(operator == "e")
    System.exit(0): //quit the program
Also, how can I set up a while loop to continuesly
prompt the user for an instruction until "e" is entered?import java.io.*;
import java.util.*;
import java.util.StringTokenizer;
public class blerk
     public static void main(String[] args) throws IOException
          InputStreamReader stdin = new InputStreamReader(System.in);
          BufferedReader br = new BufferedReader(stdin);
          boolean e = true;
          String str = "";
          String symbol = "";
          int value0 = 0;
          int value1 = 0;
          int value2 = 0;
          System.out.print(">");
          str = br.readLine();
          StringTokenizer st = new StringTokenizer(str, " ");
          int i = 0;
          int option = 0;
          while (st.hasMoreTokens())
               switch(i)
                    case 0:
                         symbol = st.nextToken();
                         // This part is obviously not correct. How can this be implemented to select and store the operating procedure the user enters?
                         if(symbol = "e")
                              System.exit(0);
                         }else
                         if(symbol = "c")
                         }else
                         if(symbol = "+")
                              option =
                    break;
                    case 1:
                         value0 = Integer.parseInt(st.nextToken());
                    break;
                    case 2:
                         value1 = Integer.parseInt(st.nextToken());
                    break;
                    case 3:
                         value2 = Integer.parseInt(st.nextToken());
                    break;
                    default:
                         System.out.println("format: >operator x y z");
                    break;
               i++;
          System.out.println(symbol + value0 + value1 + value2); //test
Any advice would be most appreciated.
Benjamin.

Similar Messages

  • Code for how to read an integer array from the command prompt...

    hello,
    Could anyone give me the code for how to read an integer array from the command prompt...its very urgent!..

    If you are using a recent version of Java (5 or later) you can use Scanner:
    http://java.sun.com/javase/6/docs/api/java/util/Scanner.html
    That page has some example code on it, too.

  • Problem - reading an abitrary string from the command line in basic swing

    Hi,
    I'm sorry if this problem is a bit basic, but I've only just started swing in Java. Anyway, I'm trying to adapt a basic swing version of the HelloWorld class. When I try to pass an abitrary string from the command line to the label within the class, I get the following error,
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
            at week2.HelloWorldSwing_commandline.main(HelloWorldSwing_commandline.java:31)
    Java Result: 1I must be missing something because I can't see where the problem is in the following code.
    import javax.swing.*;
    import java.awt.*;
    public class HelloWorldSwing_commandline {
        String message;
        private static void createAndShowGui(String message){
            JFrame.setDefaultLookAndFeelDecorated(true);
            JFrame frame = new JFrame("HelloWorldSwing");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JLabel label = new JLabel(message);
            Container content = frame.getContentPane();
            content.add(label);
            frame.pack();
            frame.setVisible(true);
        public static void main(String[ ] args) {
         createAndShowGui(args[1]);
    }Any help would really be appreciated.

    Hi,
    I've tried changing the index value to O in the main method, but I still get the same error.
    I'm running this in NetBeans 4.1, and when I try to run the class I get the error as listed above.
    Any ideas how to correct this error?
    Thanks

  • I'm trying to connect a subVI with my VI, they both share common variables and the subVI is not reading one of the variables from the main VI...

    I can't figure out why the subVI will not read this one particular variable from the main VI. How can I figure out how to make sure these two VI's are communicating properly?

    Yes, please post example.
    We could probably give you an answer rather quickly if you did.
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Pass a Value to Variable from the unix environment in ODI (ELT)

    Hi
    i am very new to ODI environment.
    i want know how to pass a value to variables in oracle data integrator from unix environment.
    Example:
    Variable name : Sales
    for variable name sales i want to pass the value from unix environment.
    Regards,
    Raj
    Edited by: user11137587 on Aug 19, 2009 6:26 AM

    Work Around !
    You can execute OS commands using Jython script. Probably you need to flush your enviornment variables value into a file using jython script and then read those value into ODI variable from the file.
    BUt may I know why you want to read environment variable vaules in ODI, Dont you think this will make your application less portable
    Regards,
    Amit

  • How can I read an ID-value from the LMS and insert this into an URL?

    Hi
    Right now I am struggling with a little problem. Hopefully anyone here knows the answer. For the latest course I am building (Captivate 6), it is necessary that at one point the course reads an ID-value from the LMS. After that, this ID should be inserted into an URL.
    To be more precisely: the ID must be read (getValue) from cmi.archive_id and inserted into an URL like that: http://.../archive.php?action=pdf&objectID=ARCHIVE_ID.
    Unfortunately I am more of a designer und less of a javascript-maestro (well...I am a javascript-noob to be precisely), therefore I am pretty clueless how to do that. I tried a simple executed action (run Javascript: cpEIGetValue('cmi.archive_id'); and after that open URL http://.../archive.php?action=pdf&objectID=ARCHIVE_ID), but...well...that didn't work.
    Any ideas?
    Thanks a lot in advance

    Think you'll find help looking at Jim Leichliter's website:
    http://captivatedev.com/
    He has great tutorials about JavaScript and also a widget that allows to enter a variable in URL's
    Lilybiri

  • Is it possible to read Essbase Substitution variables from ODI?

    Is it possible to read Essbase Substitution variables from ODI?

    Hi,
    You can do it with custom code, if you have a read of a blog I wrote :- http://john-goodwin.blogspot.com/2009/11/odi-series-planning-11113-enhancements.html
    About half way through I go into reading essbase sub vars using the essbase java API.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Reading commands from the command line

    Ok I've read quite a bit about streams, and I get the gist that you are suppose to open up a "stream," whether it from a file or from something else, and then you have to do all sorts of stuff to it like activate it or something, or whatever. But all I want to do is take an input from the command line, for example my name, and have it output "Hi [name]." I could swear I've done this before with a simple command like
    System.in.read() or something like that, but I read up on it and read is not a method that does that? So how does one just do a simple command line input into a variable...for what I want to do is control movement on a maze. If somebody can direct me to some documentation I would be happy as well. Thank you

    btw - "deadseasquirrels" - like the name. Have another program;-
    import java.io.*;
    import java.util.Random;
    public class Do_Writing {
       public static void main( String args[] ) throws IOException {
       BufferedReader in = new BufferedReader
                           (new InputStreamReader(System.in));
       Random rand = new Random();
       int i = 1+ rand.nextInt(10);
       String s1;
       System.out.println("Guess a number between 1 and 10");
          try {
             while ((s1 = in.readLine() ) != null) {
                // if( ... I'll leave the rest to you to figure out
                // when they get it right don't forget to include;-
                System.exit(0);
                in.close();
       catch (IOException ignore) { }                     
    }

  • I have two email accounts that are set up on the same iPad.  I cannot seem to see, read or send email from the second account

    I just set up a second email account on the same iPad but cannot seem to see, read or send email from the second account. 

    I'm using Windows 8 (not 8.1) and whatever the latest Thunderbird version is. They're both IMAP accounts. I was using Windows Live, but I couldn't get that to work, so I switched to TB. It works JUST fine for the one account, but not the other! They're identical except for the "handle". Both off my local ISP, set them up at the same time.

  • How to delete multiple variables from the variables list

    Hello,
    Iam using FrameMaker 9.0. Is there a way I can select multiple variables from the book and delete them together.
    Thanks,
    CP.

    NO in FM9. Take SQUIDDS TOOLBOX the free tool: 'Formats'
    'Formats' is a very helpful tool for 'deleting' paragraph formats, character formats, cross reference formats, table formats, color definitions and variables.
    You can delete unused one or all formats of selected. For paragraph and character you can also decide to 'add new one in catalog'.
    -Georg

  • Help reading a .txt file from the hard drive....

    Hi guys,
    Ok... I need to know how to read a .txt file from the hard drive... I have an example on how to read from a disk, but I don't have a disk drive. I could be confusing terminology, but I don't think I am. Here is the code I have for reading from a disk.. please let me know how I should change it to read from a hard drive.
    Also, when the error pops up, it says that it can't read another .txt file that is not specified in the code... any ideas how that is occuring? Please advise.
    import java.io.*;
    public class TEST {
    public static void main(String args[]) throws Exception{
    FileReader fr = new FileReader("customer.txt");
    BufferedReader bfr = new BufferedReader (fr);
    String s;
    while ((s=bfr.readLine())!= null){
    System.out.println (s);
    fr.close();
    }

    Ok... I need to know how to read a .txt file from the
    hard drive... I have an example on how to read from a
    disk, but I don't have a disk drive. I could be
    confusing terminology, but I don't think I am. Here
    is the code I have for reading from a disk.. please
    let me know how I should change it to read from a
    hard drive.The code will be the same, regardless of where the file is located. It's just the filename that will be different.
    Also, when the error pops up, it says that it can't
    read another .txt file that is not specified in the
    code... any ideas how that is occuring? Please
    advise.Probably becuase the class file (compiled version of the source code) is a different version to the source code, i.e. the source code hasn't been recompiled since the source code was changed.
    How does this relate to EJBs?

  • I installed the Adobe Reader on my ipad from the app store. I bought a subscription to transfer pdf files to word, excel. No Russian language in the settings. This is very bad!

    I installed the Adobe Reader on my ipad from the app store. I bought a subscription to transfer pdf files to word, excel. No Russian language in the settings. This is very bad!

    You already posted this five times; and you already have a conversation with Adobe staff going on in the ExportPDF forum.

  • Alerts with variables from the messages payload without BPM?

    Hi, experts:
    Is it possible to define a alert category with variables from the messages payload(for example:order_id ) without BPM?
    Regards
    Yu Ming

    Refer to
    http://searchsap.techtarget.com/tip/0,289483,sid21_gci1240902,00.html
    initially this also talk about BPM but you can check whether you can use the container variable in you case.
    How to define the container variable in ALRTCATDEF is mention in above link.
    **Points if answers find useful.
    Gaurav Jain

  • How to read a time stamp from the db without ".0" at the end

    Hi All,
    I have code that is saving the results of a query in a result set.
    When ever i read a time stamp from the db (mysql 4) it always adds ".0" to the end of it.
    I tried using the getTimeStamp, getDate, getString methods for result sets and was not able to resolve the issue.
    Am i missing something here?
    Thanks

    here is the code
    public static Table executeSelect(Connection conn, String qry)
         throws SQLException {
              Statement stm = null;
              ResultSet rs = null;
              try {
                   stm = conn.createStatement();
                   rs = stm.executeQuery(qry);
                   Table t = new Table(rs);
                   return t;
              } finally {
                   close(null,stm,rs);
    Basically the user is asked to enter the query and the connection settings and then i retrieve the data and return a table.
    Now if i try to print the value of the time stamp from the result set it adds a a .0
    So for example if am running the following
    select mod_ts from temp limit 1;
    | mod_ts |
    | 2007-12-28 09:32:58 |
    1 row in set (0.00 sec)
    When i print the value of the time stamp it gets printed as 2007-12-28 09:32:58.0
    The following code is used to generate a table from the result set
    public Table(ResultSet rs) throws SQLException {
              ResultSetMetaData rsmd = rs.getMetaData();
              int colCount = rsmd.getColumnCount();
              colNames = new String[colCount];
              colTypes = new int[colCount];
              for ( int i=0; i<colCount; i++) {
                   String colName = rsmd.getColumnName(i+1);
                   colNames[i] = colName;
                   int colType = rsmd.getColumnType(i+1);
                   colTypes[i] = colType;
              while ( rs.next()) {
                   if ( data == null) {
                        data = new ArrayList<List>();
                   List<Object> row = new ArrayList<Object>();
              for ( int i=0; i<colCount; i++) {
                   Object ob = rs.getObject(colNames);
                   row.add(ob);
              data.add(row);
    Now when i print the values in the result set it adds a .0 to the end of the time stamp
    I also tried using getTimeStamp for a result set and the same problem still existed

  • HT201320 how do i set up read receipts for emails from the iphone?

    how do i set up read receipts for emails from the iphone?

    That is not a feature of the Mail app. Check with your email provider to see if it's a service they offer.

Maybe you are looking for