Java Wrong Output

After two weeks I finally got my project to run only its not outputting all the information that is suppose to.
My output should display the dollar amount along with the tax catergory, but its only displaying the tax category, can someone please assist me in locating what am doing wrong.
Correct Output: The tax rate category for an annual salary of 34400 is 3.
My Ouput: The tax rate category for annual salary of 6
* AnnualSalary.java
* Johnise Felder
* This program should display the annual salary and tax category.
package annualsalary;
* @author felde301
import javax.swing.JOptionPane;
public class AnnualSalary {
/** Creates a new instance of AnnualSalary */
public AnnualSalary() {
* @param args the command line arguments
public static void main(String[] args) {
     float annualsalary = 0;
     int taxratecategory = 0;
     String input =
JOptionPane.showInputDialog (null,"Enter an annual salary",
     "Input Dialog Demo",
JOptionPane.QUESTION_MESSAGE);
annualsalary = Integer.parseInt(input);
if (annualsalary < 15000){
taxratecategory = 1;
else if (annualsalary > 15000 && annualsalary < 25000)
taxratecategory = 2;
else if (annualsalary > 25001 & annualsalary < 40000)
taxratecategory = 3;
else if (annualsalary > 400001 & annualsalary < 65000)
taxratecategory = 4;
else if (annualsalary > 65001 & annualsalary < 80000)
taxratecategory = 5;
else if (annualsalary > 80000)
taxratecategory = 6;
//end if
//display the result
JOptionPane.showMessageDialog(null,"The tax rate category for an annual salary of:" + taxratecategory);
}

hi,
take your modified code
* AnnualSalary.java
* Johnise Felder
* This program should display the annual salary and tax category.
package annualsalary;
* @author felde301
import javax.swing.JOptionPane;
public class AnnualSalary {
/** Creates a new instance of AnnualSalary */
public AnnualSalary() {
* @param args the command line arguments
public static void main(String[] args) {
float annualsalary = 0;
int taxratecategory = 0;
String input =
JOptionPane.showInputDialog (null,"Enter an annual salary",
"Input Dialog Demo",
JOptionPane.QUESTION_MESSAGE);
annualsalary = Integer.parseInt(input);
if (annualsalary < 15000){
taxratecategory = 1;
else if (annualsalary >= 15000 && annualsalary <= 25000)
taxratecategory = 2;
else if (annualsalary >= 25001 && annualsalary <= 40000)
taxratecategory = 3;
else if (annualsalary >= 400001 && annualsalary <= 65000)
taxratecategory = 4;
else if (annualsalary > 65001 && annualsalary <= 80000)
taxratecategory = 5;
else if (annualsalary >= 80000)
taxratecategory = 6;
//end if
//display the result
JOptionPane.showMessageDialog(null,"The tax rate category for an annual salary of:" + taxratecategory);
}

Similar Messages

  • Report is giving wrong output while running in Background ?

    Hi,
    We have a report program which gives the correct output while running it in forground(or manually) but when we run it in backgroud it gives the wrong output. (The printout goes to the wrong printer.)
    I've read in a SAP doc that:
    NEW-PAGE PRINT ON  even gives unpredictable
    results when the print parameters are incomplete; and it suggested to use FM 'GET_PRINT_PARAMETERS to validate the print parameters before NEW-PAGE PRINT ON event . I tried the same but still our report is sending the printout to the wrong printer while running it in background.
    Other events used in the program are AT NEW and AT LAST .
    Can anyone confirm me NEW-PAGE PRINT ON, AT NEW and AT LAST  events work correctly in background mode also.
    Thanks,
    Bhavana

    hi
    good
    NEW-PAGE PRINT ON should be work in the background also,check your syntax with the below syntax,if still it is going to the different printer in the background than check with the configuration setting of printer for the particular report that you r printing,sometime it happens that even in the foreground the correct printer ideanfies but in the background that same printer didnt identify.
    NEW-PAGE PRINT ON
        NEW-SECTION
        PARAMETERS pripar
        ARCHIVE PARAMETERS arcpar
        NO DIALOG.
      DO 440 TIMES.
        WRITE (3) sy-index.
      ENDDO.
      NEW-PAGE PRINT OFF.
    ENDFORM.
    thanks
    mrutyun^

  • Concurrent generating wrong output format with TEXT as output type

    Hi,
    I have create a custom rdf and set TEXT as its output type.
    I want the text output to be specific format but the concurrent is not generating the exact expected output.
    Expected Output:
    <?xml version="1.0" standalone="no"?>
    <!DOCTYPE labels SYSTEM "label.dtd">
    <labels FORMAT="E:WIPMATX.ZPL" _QUANTITY="1" _PRINTERNAME="Printer
    1" _JOBNAME="LBL101">
    <label>
    <variable name="$$WIP_ENTITY_NAME$$">BLFTOP</variable>
    <variable name="$$WIP_ENTITY_NAME$$">BLFTOP14</variable>
    <variable name="COM">19AWG</variable>
    <variable name="LOT_NUMBER"></variable>
    <variable name="ASSEMBLY">A05A0084-1</variable>
    <variable name="QUANTITY_ISSUED">0</variable>
    </label>
    </labels>
    *Wrong Output:*
    <?xml version="1.0" standalone="no"?>
    <!DOCTYPE labels SYSTEM "label.dtd">
    <labels _FORMAT="E:WIPMAT_X.ZPL" _QUANTITY="1" _PRINTERNAME="Printer
    1" _JOBNAME="LBL101">
    <label>
    <variable name="$$WIP_ENTITY_NAME$$"> BLFTOP </vari
    </variable>
    <variable name="$$WIP_ENTITY_NAME$$"> BLFTOP
    BLFTOP14</variable>
    <variable name="COM">19AWG</variable>
    <variable name="LOT_NUMBER"></variable>
    <variable name="ASSEMBLY">A05A0084-1</variable>
    <variable name="QUANTITY_ISSUED">0</variable>
    </label>
    </labels>
    And Actually i am trying to generate this output format type because , wer are using Zebra Printer to print lable and it is a XML enabled bprinter and understand this specifice XML DTD type. We found when set Output type to XML, it was not generating XML in accordance with DTD which Zebra printer understand Hence we are tring to use TEXT output.
    Please suggest.
    Edited by: user5499188 on Oct 3, 2011 12:12 AM
    Edited by: user5499188 on Oct 3, 2011 12:13 AM
    Edited by: user5499188 on Oct 3, 2011 12:14 AM
    Edited by: user5499188 on Oct 3, 2011 12:23 AM

    I get the solution for this issue.
    The solution is to use XML Publisher etext temaplate.
    Etext is used to get text output in any format.
    Regards, :)

  • WRONG OUTPUT

    Hi all,
    i am getting wrong output when executing the below code
    i.e the output is coming regard less of the order number  in select statement.
    Kindly please help me.
    REPORT  ZTEMP2.
    TYPES: BEGIN OF TY_BKPF,
           MONAT TYPE MONAT,
           BUDAT TYPE BUDAT,
           BELNR TYPE BELNR_D,
           GJAHR TYPE GJAHR,
           BUKRS TYPE BUKRS,
    END OF TY_BKPF.
    TYPES: BEGIN OF TY_BSEG,
           BUKRS TYPE BUKRS,
           BELNR TYPE BELNR_D,
           GJAHR TYPE GJAHR,
           HKONT TYPE HKONT,
           WRBTR TYPE WRBTR,
           SGTXT TYPE SGTXT,
           AUFNR TYPE AUFNR,
    END OF TY_BSEG.
    TYPES: BEGIN OF TY_COLL,
           MONAT TYPE MONAT,
           BUDAT TYPE BUDAT,
           BELNR TYPE BELNR_D,
           WRBTR TYPE WRBTR,
           SGTXT TYPE SGTXT,
    END OF TY_COLL.
    DATA: TOT LIKE BSEG-WRBTR.
    DATA: IT_BKPF TYPE TABLE OF TY_BKPF,
          WA_BKPF TYPE TY_BKPF,
          IT_BSEG TYPE TABLE OF TY_BSEG,
          WA_BSEG TYPE TY_BSEG,
          IT_COLL TYPE TABLE OF TY_COLL,
          WA_COLL TYPE TY_COLL.
    SELECTION-SCREEN: BEGIN OF BLOCK B1.
    SELECT-OPTIONS: S_HKONT FOR WA_BSEG-HKONT memory id one,
                    S_AUFNR FOR WA_BSEG-AUFNR memory id twq,
                    S_BELNR FOR WA_BKPF-BELNR memory id twe,
                    S_BUDAT FOR WA_BKPF-BUDAT memory id two.
    SELECTION-SCREEN: END OF BLOCK B1.
    START-OF-SELECTION.
    SELECT MONAT
           BUDAT
           BELNR
           GJAHR
           BUKRS FROM BKPF
           INTO TABLE IT_BKPF
           WHERE BELNR IN S_BELNR
           AND  BUDAT IN S_BUDAT.
    IF NOT IT_BKPF[] IS INITIAL.
      SELECT BUKRS
             BELNR
             GJAHR
             HKONT
             WRBTR
             SGTXT
             AUFNR FROM BSEG
             INTO TABLE IT_BSEG
             FOR ALL ENTRIES IN IT_BKPF
             WHERE HKONT IN S_HKONT
             AND AUFNR IN S_AUFNR
             AND BELNR IN S_BELNR
             AND GJAHR = IT_BKPF-GJAHR
             AND BUKRS = IT_BKPF-BUKRS.
    ENDIF.
    END-OF-SELECTION.
    SORT IT_BKPF BY MONAT.
    SORT IT_BSEG BY HKONT.
    LOOP AT IT_BKPF INTO WA_BKPF.
    Read table IT_BSEG INTO WA_BSEG WITH KEY BUKRS = WA_BKPF-BUKRS
                                             BELNR = WA_BKPF-BELNR
                                             GJAHR = WA_BKPF-GJAHR BINARY SEARCH.
    WA_COLL-BELNR = WA_BKPF-BELNR.
    WA_COLL-BUDAT = WA_BKPF-BUDAT.
    WA_COLL-WRBTR = WA_BSEG-WRBTR.
    WA_COLL-SGTXT = WA_BSEG-SGTXT.
    WA_COLL-MONAT = WA_BKPF-MONAT.
    COLLECT WA_COLL INTO IT_COLL.
    CLEAR: WA_BKPF, WA_BSEG.
    ENDLOOP.
    SORT IT_COLL BY MONAT.
    LOOP AT IT_COLL INTO WA_COLL.
        WRITE:/06 WA_COLL-BELNR,
               22 WA_COLL-BUDAT,
               32 WA_COLL-WRBTR,
               54 WA_COLL-SGTXT.
        AT end of MONAT.
          SUM.
          WRITE:/ WA_COLL-MONAT.
          WRITE:32 WA_COLL-WRBTR.
        ENDAT.
    ENDLOOP.
    Thanks in advance,
    ben2012.

    Hi,
    I tried this way to calculcate opening balance,
    but it is not working kindly suggest me.
    REPORT  ZTEMP1.
    " Types Declaration part
    TYPES: BEGIN OF TY_COLL,
           MONAT TYPE MONAT,
           BUDAT TYPE BUDAT,
           BELNR TYPE BELNR_D,
           WRBTR TYPE WRBTR,
           SGTXT TYPE SGTXT,
           TOT TYPE WRBTR,
    END OF TY_COLL.
    DATA: TOT LIKE BSEG-WRBTR.
    DATA: IT_BKPF TYPE TABLE OF TY_BKPF,
          WA_BKPF TYPE TY_BKPF,
          IT_BSEG TYPE TABLE OF TY_BSEG,
          WA_BSEG TYPE TY_BSEG,
          IT_BKPF1 TYPE TABLE OF TY_BKPF1,
          WA_BKPF1 TYPE TY_BKPF1,
          IT_BSEG1 TYPE TABLE OF TY_BSEG1,
          WA_BSEG1 TYPE TY_BSEG1,
          IT_COLL TYPE TABLE OF TY_COLL,
          WA_COLL TYPE TY_COLL.
    SELECTION-SCREEN: BEGIN OF BLOCK B1.
    SELECT-OPTIONS: S_HKONT FOR WA_BSEG-HKONT memory id one,
                    S_AUFNR FOR WA_BSEG-AUFNR memory id twq,
                    S_BELNR FOR WA_BKPF-BELNR memory id twe,
                    S_BUDAT FOR WA_BKPF-BUDAT memory id two.
    SELECTION-SCREEN: END OF BLOCK B1.
    START-OF-SELECTION.
    PERFORM SELECT1.
    PERFORM OPB.
    END-OF-SELECTION.
    PERFORM P_SELECT1.
    PERFORM P_OPB.
    PERFORM P_COLL.
    *&      Form  SELECT1
    FORM SELECT1 .
    SELECT MONAT
           BUDAT
           BELNR
           GJAHR
           BUKRS FROM BKPF
           INTO TABLE IT_BKPF
           WHERE BELNR IN S_BELNR
           AND  BUDAT IN S_BUDAT.
    IF NOT IT_BKPF[] IS INITIAL.
      SELECT BUKRS
             BELNR
             GJAHR
             HKONT
             WRBTR
             SGTXT
             AUFNR FROM BSEG
             INTO TABLE IT_BSEG
             FOR ALL ENTRIES IN IT_BKPF
             WHERE HKONT IN S_HKONT
             AND AUFNR IN S_AUFNR
             AND BELNR = IT_BKPF-BELNR
             AND GJAHR = IT_BKPF-GJAHR
             AND BUKRS = IT_BKPF-BUKRS.
    ENDIF.
    ENDFORM.                    " SELECT1
    *&      Form  OPB
    FORM OPB .
    SELECT MONAT
           BUDAT
           BELNR
           GJAHR
           BUKRS FROM BKPF
           INTO TABLE IT_BKPF1
           WHERE BELNR IN S_BELNR
           AND  BUDAT < S_BUDAT+3(8).
    IF NOT IT_BKPF1[] IS INITIAL.
      SELECT BUKRS
             BELNR
             GJAHR
             HKONT
             WRBTR
             SGTXT
             AUFNR FROM BSEG
             INTO TABLE IT_BSEG1
             FOR ALL ENTRIES IN IT_BKPF1
             WHERE HKONT IN S_HKONT
             AND AUFNR IN S_AUFNR
             AND BELNR = IT_BKPF1-BELNR
             AND GJAHR = IT_BKPF1-GJAHR
             AND BUKRS = IT_BKPF1-BUKRS.
    ENDIF.
    ENDFORM.                    " OPB
    *&      Form  P_SELECT1
    FORM P_SELECT1 .
    SORT IT_BKPF BY MONAT.
    SORT IT_BSEG BY HKONT.
    LOOP AT IT_BSEG INTO WA_BSEG.
      READ TABLE IT_BKPF INTO WA_BKPF WITH KEY BUKRS = WA_BSEG-BUKRS
                                               BELNR = WA_BSEG-BELNR
                                               GJAHR = WA_BSEG-GJAHR BINARY SEARCH.
    IF sy-subrc EQ 0.
    WA_COLL-BELNR = WA_BKPF-BELNR.
    WA_COLL-BUDAT = WA_BKPF-BUDAT.
    WA_COLL-WRBTR = WA_BSEG-WRBTR.
    WA_COLL-SGTXT = WA_BSEG-SGTXT.
    WA_COLL-MONAT = WA_BKPF-MONAT.
    COLLECT WA_COLL INTO IT_COLL.
    endif.
    CLEAR: WA_BKPF, WA_BSEG.
    ENDLOOP.
    ENDFORM.                    " P_SELECT1
    *&      Form  P_OPB
    FORM P_OPB .
    SORT IT_BKPF1 BY MONAT.
    SORT IT_BSEG1 BY HKONT.
    LOOP AT IT_BSEG1 INTO WA_BSEG1.
      READ TABLE IT_BKPF1 INTO WA_BKPF1 WITH KEY BUKRS = WA_BSEG1-BUKRS
                                                 BELNR = WA_BSEG1-BELNR
                                                 GJAHR = WA_BSEG1-GJAHR BINARY SEARCH.
    IF sy-subrc EQ 0.
    WA_COLL-TOT = WA_BSEG1-WRBTR.
    COLLECT WA_COLL INTO IT_COLL.
    endif.
    CLEAR: WA_BKPF1, WA_BSEG1.
    ENDLOOP.
    ENDFORM.                    " P_OPB
    *&      Form  P_COLL
    FORM P_COLL .
    SORT IT_COLL BY MONAT.
    LOOP AT IT_COLL INTO WA_COLL.
        WRITE:/06 WA_COLL-BELNR,
               22 WA_COLL-BUDAT,
               32 WA_COLL-WRBTR,
               54 WA_COLL-SGTXT.
        AT end of MONAT.
          SUM.
          WRITE:/ WA_COLL-MONAT.
          WRITE:32 WA_COLL-WRBTR.
          WRITE: WA_COLL-TOT.  " getting value 0
        ENDAT.
    ENDLOOP.
    ENDFORM.                    " P_COLL

  • Mainframe problem - java -version output : Error: unable to allocate

    Hi,
    I am calling "java -version" command from my java program. my program is executing well but when it comes to execute this command using Java Runtime it giving following error.
    java -version output : Error: unable to allocate 67108864 bytes for GC in j9vmem_reserve_memory.
    Error: unable to allocate 53686784 bytes for GC in j9vmem_reserve_memory.
    Error: unable to allocate 42949120 bytes for GC in j9vmem_reserve_memory.
    Error: unable to allocate 34359296 bytes for GC in j9vmem_reserve_memory.
    Error: unable to allocate 27487232 bytes for GC in j9vmem_reserve_memory.
    JVMJ9VM015W Initialization error for library j9jit23(11): cannot initialize JIT
    Could not create the Java virtual machine.
    and pogram continue executing.
    is any body have idea why it is behaving like this and wht needs to be done.
    this program i am writing for IBM mainframe machine.

    java -version output : Error: unable to allocate 67108864 bytes for GC in j9vmem_reserve_memory.
    Error: unable to allocate 53686784 bytes for GC in j9vmem_reserve_memory.
    Error: unable to allocate 42949120 bytes for GC in j9vmem_reserve_memory.
    Error: unable to allocate 34359296 bytes for GC in j9vmem_reserve_memory.
    Error: unable to allocate 27487232 bytes for GC in j9vmem_reserve_memory.
    JVMJ9VM015W Initialization error for library j9jit23(11): cannot initialize JIT
    Could not create the Java virtual machine.As a guess
    1. Environment is messed up
    2. Install of java is messed up.
    You might look for command line options that allow you to change the heap size. Try making it smaller.
    You might also want to verify that the 'java' you are running is actually the binary that you think it is, versus a script/link to someplace weird.

  • Wrong output from filter

    Hi everyone, 
    I'm using an equi-ripple bandpass filter for my ECG signal and getting wrong outputs. Any idea why?
    Regards,
    Gerard
    Attachments:
    filter.JPG ‏10 KB

    Hi Gerard,
    What kind of wrong outputs are you getting with the filter?  Furthermore what kind of signal are you getting from your ECG signal?  Would it be possible to put the vi on the discussion forum?
    Regards
    Nadim
    Applications Engineering
    National Instruments

  • VARRAY colletion type retirval from java , Wrong data ???? retrieved.

    Hi all,
    I am trying to retirve VARRAY collection type created in oracle from Java. It gives the wrong results as below:
    ********Fetch Starts....********
    ********Row 1 :
    Array is of type MY_UID.STRING_VARRAY
    Array is of length 2
    index 0 = ???
    index 1 = ???
    ********Fetch Ends....********
    Note: I nls_charcterset12.jar, classes12.jar are included in project class path.
    After breaking my head for two decided to request for help from big brains out there.
    For understanding, the code is attached and any help would be appriciated on this regard.
    Advance Thanks,
    Venkat
    The Code:
    import java.sql.*;
    import oracle.sql.*;
    import oracle.jdbc.oracore.Util;
    import oracle.jdbc.*;
    public class VArrayManipulation
    public static void main (String args[])
    throws Exception
    // DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    // The sample retrieves an varray of type "STRING_VARRAY",
    // materializes the object as an object of type ARRAY.
    // A new ARRAY is then inserted into the database.
    // String url = "<connection url>";
    // Connect to the database
    Connection conn =null;
    // DriverManager.getConnection (url, "<user>" , "<password>");
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    conn = DriverManager.getConnection(
    "jdbc:oracle:thin:@localhost:1521:system", "my_uid","my_password");
    conn.setAutoCommit (false);
    // Create a Statement
    Statement stmt = conn.createStatement ();
    try
    stmt.execute ("DROP TABLE sample_varray_table");
    stmt.execute ("DROP TYPE string_varray");
    catch (SQLException e)
    //Exceptions will be thrown if Table and types doesnt exist . Ignore this
    stmt.execute ("CREATE TYPE string_varray AS VARRAY(10) OF VARCHAR2(100)");
    stmt.execute ("CREATE TABLE sample_varray_table (acol string_varray)");
    //Insert using SQL
    stmt.execute ("INSERT INTO sample_varray_table VALUES (string_varray('Test1', 'Test2'))");
    ResultSet rs = stmt.executeQuery("SELECT acol FROM sample_varray_table");
    printResultSet (rs);
    //Insert using ArrayDescriptor
    // create a new ARRAY object
    String arrayElements[] = { "Test3", "Test4" };
    ArrayDescriptor desc = ArrayDescriptor.createDescriptor
    ("STRING_VARRAY", conn);
    ARRAY newArray = new ARRAY(desc, conn, arrayElements);
    PreparedStatement ps =
    conn.prepareStatement ("insert into sample_varray_table values (?)");
    ((OraclePreparedStatement)ps).setARRAY (1, newArray);
    ps.execute ();
    rs = stmt.executeQuery("SELECT acol FROM sample_varray_table");
    printResultSet (rs);
    // Close all the resources
    rs.close();
    ps.close();
    stmt.close();
    conn.close();
    public static void printResultSet (ResultSet rs)
    throws SQLException
    System.out.println("********Fetch Starts....********");
    int line = 0;
    while (rs.next())
    line++;
    System.out.println("********Row "+line+" : ");
    ARRAY array = ((OracleResultSet)rs).getARRAY (1);
    System.out.println ("Array is of type "+array.getSQLTypeName());
    System.out.println ("Array is of length "+array.length());
    // get Array elements
    String[] values = (String[]) array.getArray();
    for (int i=0; i<values.length; i++)
    System.out.println("index "+i+" = "+values[i] );
    System.out.println("********Fetch Ends....********");
    }

    import java.sql.Array;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import oracle.sql.ARRAY;
    import oracle.sql.ArrayDescriptor;
    public class test
        public static void main (String args[]) throws Exception
            DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
            Connection conn = DriverManager.getConnection
                ("jdbc:oracle:thin:@sta00077.us.oracle.com:1521:xe", "scott","tiger");
            Statement stmt = conn.createStatement ();
            try {
                stmt.execute("DROP TABLE varray_table");
                stmt.execute("DROP TYPE string_varray");
            } catch (Exception e) { }
            stmt.execute("CREATE TYPE string_varray AS VARRAY(10) OF VARCHAR2(10)");
            stmt.execute("CREATE TABLE varray_table (sv string_varray)");
            stmt.execute("INSERT INTO varray_table VALUES (string_varray('Test1', 'Test2'))");
            ResultSet rs = stmt.executeQuery("SELECT sv FROM varray_table");
            printResultSet(rs);
            String arrayElements[] = { "Test3", "Test4", "Test5" };
            ArrayDescriptor desc = ArrayDescriptor.createDescriptor("STRING_VARRAY", conn);
            ARRAY newArray = new ARRAY(desc, conn, arrayElements);
            PreparedStatement ps = conn.prepareStatement("INSERT INTO varray_table VALUES (?)");
            ps.setArray(1, (Array)newArray);
            ps.execute();
            rs = stmt.executeQuery("SELECT sv FROM varray_table");
            printResultSet(rs);
            rs.close();
            ps.close();
            stmt.close();
            conn.close();
        public static void printResultSet (ResultSet rs) throws Exception
            System.out.println("******** Fetch Starts ********");
            int line = 0;
            while (rs.next()) {
                line++;
                System.out.println("*** Row " + line + " ***");
                Array array = rs.getArray(1);
                String[] values = (String[])array.getArray();
                System.out.println ("Array is of type " + array.getBaseTypeName());
                System.out.println ("Array is of length " + values.length);
                for (int i = 0; i < values.length; i++)
                    System.out.println("Index " + i + " = " + values);
    System.out.println("******** Fetch Ends ********");

  • Wrong output by pgrep -f command

    Hello!
    I have created a monitor, that check the running instances of a process under Linux (SLES11SP3) with SCOM 2012 SP1 CU4.
    As monitor type I chose the "Microsoft.Unix.ShellCommand.TwoState.MonitorType" (which I have used successfully many times) and as shellcommand to get an output of the process count I used the shell command:
    pgrep -l cron | grep -vc grep (in this example "cron"; the process name is irrelevant to our problem)
    In the ssh session on the linux machine this command works fine and shows an output of "1", as exactly one cron is running. The SCOM Agent on the other hand shows an output (StdOut) of "2" on the same system (I have double checked
    this with the winrm command to execute shellcommands from xml, too).
    After some thinking I noticed that the "|grep -vc grep" part was not necessary (because pgrep does not list the "grep" process) and switched it with "| wc -l". Unfortunately the SCOM Agent and the winrm command for shellcommands
    still showed a "StdOut" of "2" although only "1" cron was running on the system.
    Now comes the interesting part:
    Instead of "pgrep -f" I chose "pgrep -l" and finally the "StdOut" in SCOM matched the one on the system. So after another round of testing I found out that only "pgrep -f" seem to deliver a wrong "StdOut".
    I can post proof for that, unfortunately Im on a tight schedule today, so if needed I can provide it on monday.
    Maybe one of you has an idea, why scom always adds "1" when using "pgrep -f"?

    If I understand correctly, you are comparing two situations:
    1)  You manually run 'pgrep' in at a shell command prompt after using ssh to login to the Linux server
    2)  The OpsMgr agent runs 'pgrep' as part of a monitor
    And you are getting different results from the two cases.
    In case #2, doesn't the command line you are giving to OpsMgr actually starts with /bin/sh -c, so that you can specify a command line that contains pipes, etc. which are executed by /bin/sh?  If so, then the OpsMgr agent is spawning a /bin/sh
    process that has the pgrep command line as an argument, including the process name that pgrep is looking for.  /bin/sh is then in turn spawning the pgrep process.  The "extra" process that pgrep is finding is the /bin/sh process that is spawned by
    the OpsMgr agent.  You won't have that process in case #1 when you are just running pgrep manually at a shell prompt.
    Michael Kelley, Lead Program Manager, Open Source Technology Center

  • Wrong output when executed in UNIX machine

    Hi All,
    We have created a java class which takes a file name as command line arguments and trying to test whether that file which has taken from command-line is accessible if it is already in use (like copying from/to other path). For this we are passing filename as argument to FileInputStream Class .
    This java class when executed in windows machine is giving expected output i.e. throwing Exception if the file is already in use. But the same code when ran from UNIX machine, there it is not giving expected result as mentioned above. Can anyone please help us in resolving this problem?
    Thanks in Advance

    Not sure if this has anything to do with it, but did ftp the text file up to the UNIX machine? If you did, were you using ascii mode?
    Windows:
    file in  use.becomes
    file in use.^Min unix when I transfer the file using the binary mode.
    -J

  • Reading a UTF-8 Web encoded page - Wrong output

    Dear All,
    I have used Java to fetch Greek web pages encoded in ISO-8859-7 without any problems. The HTML source along with the greek letters shows up to my console (Eclipse) just fine.
    However now that i am trying to fetch a web page encoded in UTF-8 i get question marks in some characters. So far i had the best results by using the following code :
    byte[]b=line.getBytes();
    String newLine=new String(b,"UTF-8");
    System.out.println(newLine);
    The above outputs questionmarks for 2 specific Greek letters. I have tried everything yet no luck...can someone help ??

    Dear All,
    I have used Java to fetch Greek web pages encoded in
    ISO-8859-7 without any problems. The HTML source
    along with the greek letters shows up to my console
    (Eclipse) just fine.
    However now that i am trying to fetch a web page
    encoded in UTF-8 i get question marks in some
    characters. So far i had the best results by using
    the following code :
    byte[]b=line.getBytes();
    String newLine=new String(b,"UTF-8");
    System.out.println(newLine);
    The above outputs questionmarks for 2 specific Greek
    letters. I have tried everything yet no luck...can
    someone help ??Remember that the Strings in java are always utf-8, its the byte arrays that have different encodings. When you do
    byte[]b=line.getBytes();
    you are translating it into a byte array with default encoding, which would be something to the affect of iso8859_1, hence you end up losing the greek characters.
    Then you do
    String newLine=new String(b,"UTF-8");
    telling that create a String(which is always going to be utf8) from a byte array with encoding utf-8 while when you created the byte array it was iso8859-1 so there is no way you would get the right String

  • Java binding - output log file

    I have successfully implemented a simple java binding interface, but I am having some issues with the java class and I would like to do some debugging.
    I was under the assumption that system.out.pritntln statements in the code would simply redirect to the default domain.log, however I don't see any of my output.
    Does anyone know how I should go about debugging the external class? I am sure that using log4j would be more appropriate, but for now, I just want some simple output to let me know the health and status.
    Thanks in advance.

    solved by adjusting the opmn config output to re-direct the stdout

  • Java generation output

    I invoque the following command line :
    java -classpath xxx/toto.jar toto.Tool file.g
    which generates files I want but where I want, the output directory is bad
    how to indicate to the compiler which directory to put the generated files ?
    in c++ we use -o as an option
    I don't find the equivalent for java..

    That option is for specifying destination of.class
    files for javac. I don't think that's what the OP
    wants.Ahem. "how to indicate to the compiler which
    directory to put the generated files ?" That's
    exactly what "-d" does.Ahem. Reread the whole command line. The OP is running a class with "java", not compiling with "javac". The OP has the terminology messed up. I think the OP's class itself generates files.

  • Simple calculation - but wrong output?

    I have:
    System.out.println(3 * 0.2);But the outputs 0.6000000000000001 instead of 0.6.
    Why?

    [Performing exact calculations with floating-point numbers|http://java.sun.com/developer/JDCTechTips/2001/tt0807.html#tip1]
    [Some things you should know about floating-point arithmetic|http://java.sun.com/developer/JDCTechTips/2003/tt0204.html#2].
    [What Every Computer Scientist Should Know About Floating-Point Arithmetic|http://docs.sun.com/source/806-3568/ncg_goldberg.html]
    [Floating point - From Wikipedia, the free encyclopedia|http://en.wikipedia.org/wiki/Floating_point]
    ~

  • Exec() - G77 Fortran blocks read(*,*)  until Java closes output stream.

    This is my first post!
    I have a program in fortran using G77 from GNU. When I start the program and write to the output stream I have to close() the stream for the message to arrive at the other end. G77 seems to need Java to close the stream for the message to be sent.
    Then, the stream is forever closed and can not be re-obtained for subsequent writes.
    I do not need to close() with microsoft fortran. It works fine with a simple flush().
    My code for Microsoft is below, followed by same code for G77:
    Any ideas?
    Disciple285
    // write to stream with Microsoft Fortran
    std_out.println(message);
    std_out.flush();
    // write to stream with G77 Fortran
    std_out.println(message);
    std_out.close();

    Hi:
    The internal OJVM is not affected by your installations of any other Sun JDK on the server.
    So you can not upgrade your internal OJVM without upgrading the entire DB.
    Oracle 10g includes a JDK 1.4 runtime, 11g a 1.5 runtime and so on.
    If you can upgrade your Oracle 9.2.0.8 to a 10g release you can then compile the code, if not you should re-write the code to compile with an standard JDK 1.3 release.
    Best regards, Marcelo.

  • Checking for files in a folder -- Wrong output

    Hi guys,
    I'm writing a simple program, I have to check for 6 files (hardcoded, they will never change) if they are in certain directories/paths.
    The problem is, I think I have a problem in my IF statements, because it continueally returns false.
    The paths are on networked drives, does that make a difference?
    I'm rather stuck on this one, any help would be appreaciated.
    (some paths/file names have been replaced by "xxxxxxxxx", for security)
    * Checks for files in a directory, prints results.
    * @author Mitchell
    * @version 0.2
    * @date 28 Jul '05
    import java.awt.*;
    import java.io.*;
    import java.lang.Object;
    import javax.swing.*;
    import java.util.*;
    public class FileCheck extends JFrame
        //declare filenames/paths, add more if needed.
        String fileName1 = "file it2_load.txt";
        String fileName2 = "mo_batch.txt";
        String fileName3 = "mo_bcp.txt";
        String fileName4 = "mo_load.txt";
        String fileNameX = "IT2_1000_yyyymmdd.txt";
        String fileNameY = "IT2_2000_yyyymmdd.txt";
        //declare directories to search
        String fileLocation1 = "\\\\xxxxxxxxx\\aus_bear\\Patrol";
        String fileLocation2 = "\\\\xxxxxxxxx\\nz_bear\\Patrol";
        String fileLocation3 = "\\\\xxxxxxxxx\\bear\\remote\\RTS";
        String fileLocation4 = "\\\\xxxxxxxxx\\bear\\remote\\RTS";
        //declares array for filename storage. Change if needed.
        File fileNamesArray1[];
        File fileNamesArray2[];
        File fileNamesArray3[];
        File fileNamesArray4[];
        //set path to find files
        File filePath1 = new File(fileLocation1);
        File filePath2 = new File(fileLocation2);
        File filePath3 = new File(fileLocation2);
        File filePath4 = new File(fileLocation2);
        //string buffer to store results
        StringBuffer results = new StringBuffer();
        //start of FileCheck method
        public FileCheck()
            //collects all filenames from pre-set path1
            fileNamesArray1 = filePath1.listFiles();
            results.append("This program checks for files in given folders."
                            +"\nTRUE = File does exist in folder."
                            +"\nFALSE = File does not exist in folder.\n\n");
            results.append(fileLocation1 + "\n");
            //start for loop1 - check for pre-set filenames in path1
            for(int i=0; i < fileNamesArray1.length; i++)
                    if( fileName1.equals(fileNamesArray1.toString()))
    results.append("PATH1 >> " + fileNamesArray1[i] + " >> TRUE\n" + fileNamesArray1[i].lastModified());
    else if( fileName2.equals(fileNamesArray1[i].toString()))
    results.append("PATH1 >> " + fileNamesArray1[i] + " >> TRUE\n" + fileNamesArray1[i].lastModified());
    else if( fileName3.equals(fileNamesArray1[i].toString()))
    results.append("PATH1 >> " + fileNamesArray1[i] + " >> TRUE\n" + fileNamesArray1[i].lastModified());
    else if( fileName4.equals(fileNamesArray1[i].toString()))
    results.append("PATH1 >> " + fileNamesArray1[i] + " >> TRUE\n" + fileNamesArray1[i].lastModified());
    else
    results.append("PATH1 >> " + fileNamesArray1[i] + " >> FALSE\n");
    } //end for loop1
    //collects all filenames from pre-set path2
    fileNamesArray2 = filePath2.listFiles();
    results.append("\n" + fileLocation2 + "\n");
    //start for loop2 - check for pre-set filenames in path2
    for(int j=0; j < fileNamesArray2.length; j++)
    if( fileName2.equals(fileNamesArray2[j].toString()))
    results.append("PATH2 >> " + fileNamesArray2[j] + " >> TRUE\n" + fileNamesArray2[j].lastModified());
    else if( fileName2.equals(fileNamesArray2[j].toString()))
    results.append("PATH2 >> " + fileNamesArray2[j] + " >> TRUE\n" + fileNamesArray2[j].lastModified());
    else if( fileName3.equals(fileNamesArray1[j].toString()))
    results.append("PATH2 >> " + fileNamesArray2[j] + " >> TRUE\n" + fileNamesArray2[j].lastModified());
    else if( fileName4.equals(fileNamesArray1[j].toString()))
    results.append("PATH2 >> " + fileNamesArray2[j] + " >> TRUE\n" + fileNamesArray2[j].lastModified());
    else
    results.append("PATH2 >> " + fileNamesArray2[j] + " >> FALSE\n");
    } //end for loop2
    //collects all filenames from pre-set path1
    fileNamesArray3 = filePath3.listFiles();
    results.append("\n" + fileLocation3 + "\n");
    //start for loop3 - check for pre-set filenames in path1
    for(int k=0; k < fileNamesArray3.length; k++)
    if( fileNameX.equals(fileNamesArray3[k].toString()))
    results.append("PATH3 >> " + fileNamesArray3[k] + " >> TRUE\n" + fileNamesArray3[k].lastModified());
    else
    results.append("PATH3 >> " + fileNamesArray3[k] + " >> FALSE\n");
    } //end for loop3
    //collects all filenames from pre-set path4
    fileNamesArray4 = filePath3.listFiles();
    results.append("\n" + fileLocation4 + "\n");
    //start for loop4 - check for pre-set filenames in path1
    for(int l=0; l < fileNamesArray4.length; l++)
    if( fileNameY.equals(fileNamesArray4[l].toString()))
    results.append("PATH4 >> " + fileNamesArray4[l] + " >> TRUE\n" + fileNamesArray4[l].lastModified());
    else
    results.append("PATH4 >> " + fileNamesArray4[l] + " >> FALSE\n");
    } //end for loop4
    //construct displaybox for results
    JTextArea textArea = new JTextArea( results.toString() );
    textArea.setEditable(false); //disables modification of results
    Container container = getContentPane();
    container.add( new JScrollPane( textArea ) );
    setSize( 500, 500 ); // set window size
    setVisible( true ); //allow visibility
    //main
    public static void main (String args[])
    FileCheck window = new FileCheck();

    You could try using the File.exists() method.
    The paths are on networked drives, does that make a difference?Try the above on a local file and a networked file.
    I'm writing a simple program, Actually a simple program would be something like:
    File file = new File("xxx");
    System.out.println(file.exists());No need to include all the code you posted.
    http://www.physci.org/codes/sscce.jsp

Maybe you are looking for