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.

Similar Messages

  • How can i run application client from the command prompt ?

    Hi,
    I'm new to java & EJB. so can any body tell me the command to run the application client from the command prompt. Here is the code to print hello world:
    /* Remote interface */
    public interface Hello extends javax.ejb.EJBObject
         public String hello() throws      java.rmi.RemoteException;
    /* Home interface */
    public interface HelloHome extends javax.ejb.EJBHome
         Hello create() throws java.rmi.RemoteException, javax.ejb.CreateException;
    /* Stateless session bean class */
    public class HelloBean implements javax.ejb.SessionBean
         private javax.ejb.SessionContext ctx;
         public void ejbCreate(){
              System.out.println("ejbcreate()");
         public void ejbRemove(){
              System.out.println("ejbRemove()");
         public void ejbActivate(){
              System.out.println("ejbActivate()");
         public void ejbPassivate(){
              System.out.println("ejbejbPassivate()");
         public void setSessionContext(javax.ejb.SessionContext ctx){
              this.ctx=ctx;
         public String hello(){
              System.out.println("hello()");
              return "Hello, world!";
    /*Client class */
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import java.util.Properties;
    public class HelloClient
         public static void main(String[] args) throws Exception{
              Properties props=System.getProperties();
              Context ctx=new InitialContext(props);
              Object obj=ctx.lookup("HelloHome");
              HelloHome home=(HelloHome)javax.rmi.PortableRemoteObject.narrow(obj,HelloHome.class);
              Hello hello=home.create();
              System.out.println(hello.hello());
              hello.remove();
    I have stored .java files in c:\ejb
    I have successfully created the .class files using javac command in the following directory :
    c:\ejb
    I have also created Helloworld.ear file in c:\ejb using sun application server which contains the following files:
    ejb-jar-ic.jar
    app-client-ic.jar
    sun-j2ee-ri.project
    application.xml
    sun-application.xml
    Manifest.mf
    But the problem is that i'm not able to run the HelloWorld.class file successfully from the command prompt. So please suggest me the comand.
    Thanx in advance.
    Best regards,
    Pankaj

    Hi
    You can run this code from the command prompt in the same way as you run any other simple java program. The only thing is you need to set the Home and Local interfaces in the classpath.And obviously if u had deployed the bean in ur app server container, then its all over.
    And one more thing is that u need to set the provider URL in the InitialContext created in the client program.
    Thanks
    Arun B

  • 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.

  • How can I pass a value to the command prompt?

    I was wondering how can I pass a value to the command prompt with Windows and Linux? I'm more interested in Linux's system than Windows though. Is there a way to return info from the command prompt?

    Here is a snippet from http://mindprod.com/jglossexec.html that explains how in detail.
    Runtime.getRuntime().exec("myprog.exe") will spawn an external process that runs in parallel with the Java execution. In Windows 95/98/ME/NT/2000/XP, you must use an explicit *.exe or *.com extension on the parameter. It is also best to fully qualify those names so that the system executable search path is irrelevant, and so you don't pick up some stray program off the path with the same name.
    To run a *.BAT, *.CMD, *.html *.BTM or URL you must invoke the command processor with these as a parameter. These extensions are not first class executables in Windows. They are input data for the command processor. You must also invoke the command processor when you want to use the < > | piping options, Here's how, presuming you are not interested in looking at the output:
    Runtime.getRuntime( ).exec ("command.com /E:1900 /C MyBat.bat" );
    Runtime.getRuntime( ).exec ("cmd.exe /E:1900 /C MyCmd.cmd" );
    Runtime.getRuntime( ).exec ("C:\\4DOS601\\4DOS.COM /E:1900 /C MyBtm.btm" );
    Runtime.getRuntime( ).exec ("D:\\4NT301\\4NT.EXE /E:1900 /C MyBtm.btm" );
    There are also overloaded forms of exec(),
    Runtime.getRuntime( ).exec ("command.com /E:1900 /C MyBat.bat", null);
    Runtime.getRuntime( ).exec ("command.com /E:1900 /C MyBat.bat", null, "C:\\SomeDirectory");
    The second argument can be a String [], and can be used to set environment variables. In the second case, "C:\\SomeDirectory" specifies a directory for the process to start in. If, for instance, your process saves files to disk, then this form allows you to specify which directory they will be saved in.
    Windows and NT will let you feed a URL string to the command processor and it will find a browser, launch the browser, and render the page, e.g.
    Runtime.getRuntime( ).exec ("command.com http://mindprod.com/projects.html" );
    Another lower level approach that does not require extension associations to be quite as well set up is:
    Runtime.getRuntime( ).exec ("rundll32 url.dll,FileProtocolHandler http://mindprod.com/projects.html" );
    Note that a URL is not the same thing as a file name. You can point your browser at a local file with something like this: file://localhost/E:/mindprod/jgloss.html or file:///E|/mindprod/jgloss.html.
    Composing just the right platform-specific command to launch browser and feed it a URL to display can be frustrating. You can use the BrowserLauncher package to do that for you.
    Note that
    rundll32.exe url.dll,FileProtocolHandler file:///E|/mindprod/jgloss.html
    won't work on the command line because | is reserved as the piping operator, though it will work as an exec parameter passed directly to the rundll32.exe executable.
    With explicit extensions and appropriately set up associations in Windows 95/98/ME/NT/2000/XP you can often bypass the command processor and invoke the file directly, even *.bat.
    Similarly, for Unix/Linux you must spawn the program that can process the script, e.g. bash. However, you can run scripts directly with exec if you do two things:
    Start the script with #!bash or whatever the interpreter's name is.
    Mark the script file itself with the executable attribute.
    Alternatively start the script interpreter, e.g.
    Runtime.getRuntime( ).exec (new String[]{"/bin/sh", "-c", "echo $SHELL"}";

  • 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

  • How to read an audio file from the disk and play it?

    Do you know who to read an audio file from the hard disk and play it. It's for an application and not an applet. I tried with the Applet.newAudioClip(URL url) thing, but I keep getting a MalformedURLException.
    And is there a way to get the path of the file you are using? Currently I'm doing this:
    File file = new file("randomname");
    string = file.getAbsolutePath();
    file.delete();
    I'm sure there's a better way. And this is not for an applet, just a normal app.

    Below is a class that should be of use to you.
    package com.sound;
    import java.io.File;
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.Clip;
    import javax.sound.sampled.DataLine;
    public class SoundPlayer implements Runnable {
         String filename;
         public SoundPlayer(String filename){
              this.filename = filename;
              Thread t = new Thread(this);
              t.start();
         }//SoundPlayer constructor
         public void run(){
              playSound();
         }//run method
         public boolean playSound(){
              try {
                   File file = new File(filename);
                   AudioInputStream stream = AudioSystem.getAudioInputStream(file);
                   AudioFormat     format = stream.getFormat();
                   DataLine.Info info = new DataLine.Info(Clip.class, format);
                   Clip clip = (Clip)AudioSystem.getLine(info);
                   clip.open(stream);
                   clip.start();
                   while (clip.isRunning()) {
                       Thread.sleep(100);
                   clip.close();
              catch (Exception e) {
                  System.err.println("Error in run in SoundPlayer");
                   return false;
              return true;
         }//playSound() method
    }//Class SoundPlayer

  • 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

  • How to read flushed cluster array from input queue?

    Hi! I'm new to LabView. Can someone please help me?
    I want to use a subvi to read a queue which I created in another vi. The created queue holds an array of clusters that I want to unbundle in a for loop in the reading vi. But the output of the flush queue function is a string array (since the subvi has no info on what sort of queue is being input).
    I can't connect the unbundle function to a string input; can I use the type cast function to force the flush output to be a cluster? Or is there a better way to do this?
    And if so, what is the string constant I need to attach to the "type" input in the type cast function?
    And also, I'm told that the cluster is kind of like a "struct"; so is there a way to n
    ame it so that other vi's know what it is(i.e. type cast)?
    jen

    I did look at the help examples, but I couldn't find one that was sending the queue from one vi to another(well, not any that I could understand), and that was really my problem.
    I did get the thing to work when it was all in one vi.
    You bring up an interesting point about "dequeue" and "flush". Perhaps I am mistaken, but my reasoning for using flush rather than dequeue was the following:
    I am using the queue as a data buffer. I need the queue to hold a few minutes of data. This data is dumped to file upon fault event, i.e. it tells me what was going on right before the fault occurred. I need that queue to dump the data and then immediately turn around and start filling up again. I felt that holding on to the queue reference in the save-to-file routi
    ne (which involves lots of potentially slow hard disk access) might cause the object to lock and hence not be able to save right away. I don't know how LabView does threading, but if I was writing the threading routine, I would lock any object which was being executed upon in a routine to prevent data collision.
    Of course, this begs the question: does LabView lock all objects in a subroutine that is executing? Or just in the part which is unresolved? or does it lock objects at all? Perhaps I should flush the queue outside of the subroutine anyway, so that the subroutine can happily munch on the flushed array while my queue goes back to the business of collecting data?
    Am I way off base in how the threading works?
    Thanks!
    jen

  • How to read a flat file from the batch

    Hi,
    We have a requirement to read a flat file in the custom java batch in ETM2.2. We have the file at a specific location.
    can some one let me know what are the various options, we have to read a flat file.
    Thanks,
    Sharath Kumar G.

    Is it referring to some "Process X" batch?
    And why MPL/XAI with or without Configuration Tools should not be used to do this and a custom Java batch is required?

  • How can I start System Preferences from the command line?

    Hello All,
    I have an issue I'm not quite sure how to solve. I have been tasked within my business environment  with tightening security on a Mac Leopard system and I've been granted Admin Rights to do this on a temporary basis.
    The problem is as follows:
    1) The original Sys Admin that set up this system is gone, no longer available.
    2) He was a Dvorak Keyboard fan and set up the system for a Dvorak Keyboard.
    3) The system actually has a standard Apple keyboard and is marked accordingly, i.e., qwerty (Most Users in the building have stopped using this system altogether - a terrible waste of a good system - even though some of their apps can be run normally (US style qwerty settings). The command line is useless, as is texteditor.app and a few others unless you know Dvorak layout)
    5) When I open System Preferences, the Dvorak keyboard checkbox is grayed out and I cannot change it. There is no lock at the bottom of that particular screen for me to unlock.
    6) Even though I select the US Keyboard at Login, and some apps work accordingly (like MatLab for example) the terminal is borderline useless. I spent over 2 hrs yesterday doing what should have been able to be done in about 30 minutes. I estimate a frustrating and mistake prone additional 8 to 10 hours to do what is normally a a 4 hour job at the command-line.
    7) I do not have the time or desire to re-mark all the keys on the keyboard, particularly since it is not my call to do so, nor do I have the time to re-learn Dvorak touch-typing, and finally I do not want to re-load the entire system. I just want to change the darn keyboard to a standard qwerty keyboard that is somewhat useful in a terminal environment with vi, command line, etc. It's either that or I go mildly insane
    This is frustrating as all get-out. The new Admin logged in and was able to uncheck his Dvorak settings (he is not a UNIX guy, nor is he comfortable om Macs), and we were hoping this was a system wide setting, but No. We re-booted the system, I logged in, still Dvorak, and the checkbox was still grayed out.
    So I figure, short of re-loading the entre system and all the applications necesary, I can either start the Systems Preferences GUI using sudo and hopefully that will change system-wide settings, or I can delete the .AppleSetupDone file and resetup the system (if the keyboard settings are part of the setup) without spending a couple of days reloading everything and re-setting up users, networks, etc.
    Needless to say, I am hoping for the easiest and quickest solution to this extremely frustrating and  aggravating problem.
    Thanks.

    For my situation the following C# code does the job:
        Process.Start(
           @"c:\Program Files\National Instruments\CVI71\cvi.exe",
           @"c:\temp\experiment.c" );
    The file must already exist.

  • How to execute OMB scripts from the command prompt of OS

    Hi
    I want to deploy the mapping from one environment to other environment using OMB script language. But I dont want to run the OMB scripts from OMB plus COmmand prompt?
    All I need is , is there any way/scripts to access OMB command prompt from the general command prompt of the OS Machine?
    or Can I call this OMB command from java program but not JDeveloper?
    It would be a great help for me by sharing your knowledge?
    Cheers
    Pradeep

    This way from MS-DOS:
    set ORACLE_HOME=c:\oracle\OWB10gR2 (change to your Oracle Home)
    call C:\oracle\OWB10gR2\owb\bin\win32\OMBPlus.bat C:\...\my_script.tcl > C:\...\my_log.log
    my_script.tcl contains something like this:
    set OMBLOG "c:\\...\\some_kind_of.log"
    # Disconn just in case you have called a previous script
    OMBDISC
    source C:\\...\\script_with_omb_procedures.tcl
    OMBCC my_project
    OMBCONNECT CONTROL_CENTER "USER/PASSWORD@HOST:PORT:SERVICE" USE REPOSITORY 'MY_REPOSITORY_OWNER'
    OMBDCC
    DEFAULT_CONTROL_CENTER MY_CONTROL_CENTER
    proc_from_script_with_omb_procedures
    exit
    Hope this helps you to begin.
    Instead of using script_with_omb_procedures.tcl you can have your procedures directly inside my_script.tcl, but I like using a script apart to reuse my procedures.

  • How do download and install firefox from redhat command prompt step by step with commands

    How do download and install firefox from redhat 6 command prompt
    Im new to Linux so would appreciate step by step details with commands

    Is your Windows Vista 32 or 64 bit?
    To find out if your computer is running 32-bit or 64-bit Windows, do the following:
    Open System by clicking the Start button, clicking Control Panel, clicking System and Maintenance, and then clicking System.
    Under System, you can view the system type.

  • How to list a shared directory from the command line?

    My iMac is on a LAN with some windows machines and has access to a shared folder on one windows machine in particular. On the iMac, this shared computer shows up as 'tabernacle' and I can see its contents in the finder. I'd like to be able to inspect the contents of this folder using the command line but I have no idea what path to use. Can anyone tell me where to find mounted shared folders from the OSX command line?

    Open the Terminal in the /Applications/Utilities/ folder and drag it from the Finder to the open Terminal window. The path will appear.
    (54518)

  • How to read a particular word from the middle of the line from a .txt file

    BufferedReader reader = new BufferedReader(new FileReader("D:\\kiran.txt")); //given as a input
    String line = reader.readLine();
    StringBuffer sb=new StringBuffer();
    while(line!=null){
    sb.append(line);//appended to line
    line=reader.readLine();
    line=sb.toString();
    StringTokenizer st=new StringTokenizer(line); //Input to String Tokenizer
    while(st.nextToken()!=null){
    String ln=st.nextToken();
    System.out.println(ln);
    if(ln.equals("Time:")){
    System.out.println(st.nextToken());
    can any help me regarding this

    either refer this:-
    http://forum.java.sun.com/thread.jspa?threadID=5276606
    Or
    try this:-
    String str=null;
                   DataInputStream di=new DataInputStream(new FileInputStream("D:\\Test.txt"));
                   while((str=di.readLine())!=null)
                        if(str.contains("Time"))
                             int index=str.indexOf("Time");
                             str=str.substring(index,str.length());
                        System.out.println(str);
                   }

  • How to read files from the menu prompt

    Hi all the experts here, help me plz
    this is the menu
    R - Read a batch of student marks from a file
    D - Display a table of student results
    Q - Quit from the program
    when user press R the program has to read a file. The default file name is results1.txt
    but my teacher is gonna change the file name when she tests it.
    so i can't put the fixed file name. i have to read the file name from the command
    prompt
    The user will type the file name and i just have to read that file..but..its hard for the
    biginner...THX guys

    help me guys plz im really stuck man
         public char promptMenu()
              System.out.println ("R - Read a batch of student marks from a file");
              System.out.println ("D - Display a table of student results");
              System.out.println ("Q - Quit from the program");
              char answer = Keyboard.readChar();
              return answer;
    after user press 'R'
    then i have to read a file whatever the user enters..

Maybe you are looking for

  • What happened to the Lightroom 5 Beta forum? Deleted, not archived or merged?

    What happened to the Lightroom 5 Beta forum? I understand that LR5.2 is now in full release, but it would be nice if the Beta forum was locked and archived for reference. It seems to have been completely deleted, along with some detailed feedback by

  • Random KPs and random AHT 4MEM errors

    Hello, i need some advice regarding my 21.5 iMac. A little history : I bought it from the refurb 6 months ago and added 8 gig crucial ram (now 12 gig). I have been experiencing KPs with a freeware video converter (handbrake) and thought it was due to

  • How to get photos off my Windows 7 PC to my iPhone and iPad Mini?

    How do I get photos off of my Windows 7 PC to my iPhone 4S and iPad Mini automatically through iCloud?

  • How to search for a tile in store

    I need Moxilla, Safari or Google Chrome to run my software I'm using for my chiropractic office. I can't seem to find a search section in the application store to purchase this. What am I doing wrong? Chelsea Knapp

  • A question from Paris !!

    Hello guys, - My wife loves me, she bought me a MacBook Pro 17', - and i love her too, - so- Anyway, - a need some informations for a product call "fins-up". It's a system that we fixed under the mac to lift it a little- (sorry my english, - i'm fren