Cannot understand the output

class TrickyTest {
     public static void main ( String args [ ] ) {
          int i = 10 ; // line 1
          i = ++i ; // line 2
          i = i++ ; // line 3
          System . out . println ( i ); // line 4
};The answer is 11. Why not 12?

FFS!
1. NEVER write code like i = i++
2. Search the forum or google. This has been asked plenty of times.

Similar Messages

  • Cannot understand the output of x*y

    Hello All,
    I was running the following program.
    import java.io.*;
    public class Basics {
         public static void main(String[] args) {
    System.out.println("---------" + args.length + "---------");
              System.out.println("argument is " + args[1]);
    If i run the program with arguments 3+4(numbers could be anything),it runs fine ,provides the desired output.
    But if i run the program with 3*7 as its arguments it gives me the following output.
    ---------9---------
    argument is .classpath
    *Please explain why this difference in output                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Try:
    public class Basics {
      public static void main(String[] args) {
        System.out.println("---------" + args.length + "---------");
        for (int i = 0; i < args.length; i++)
          System.out.println("Argument #" + i + " is: " + args);
    It may be more revealing...

  • Cannot read the output from windows command.

    Hello
    I have the following classes
    package cmd;
    import java.io.IOException;
    public class CMD {
        public CMD(){
            ProcessBuilder pb = new ProcessBuilder()
            .command("cmd.exe","/c","del *.*")
            .redirectErrorStream(false);
            Process p;
            try {
                p = pb.start();
                StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(), "ERROR");
                // any output?
                StreamGobbler outputGobbler = new StreamGobbler(p.getInputStream(), "OUTPUT");
                // start gobblers
                outputGobbler.start();
                errorGobbler.start();
            } catch (IOException e) {
                // TODO Auto-generated catch block
            System.out.println("eee "+e.getMessage());;
        public static void main(String[] args) {
            System.out.println("x");
            new CMD();
            System.out.println("x");
    and
    package cmd;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    public class StreamGobbler extends Thread {
        InputStream is;
        String type;
        StreamGobbler(InputStream is, String type) {
            this.is = is;
            this.type = type;
        @Override
        public void run() {
            try {
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);
                String line = null;
                while ((line = br.readLine()) != null)
                    System.out.println(type + "> " + line);
            catch (IOException ioe) {
                ioe.printStackTrace();
    Please note that I cannot seee the output from wndows command : del *.* and the java class execution does not finished.
    I I will replace the above command with the dir command then the output of the command is visible.
    Would you give me a hint about how to modify the above clases in order to parse the output of the del *.* ?
    Please note that the above example is important because I am developping a tool and it is mandatory for that tool to parse the output from a windows batch command.
    Best regards,

    Please note that I cannot seee the output from wndows command : del *.* and the java class execution does not finished.
    I I will replace the above command with the dir command then the output of the command is visible.
    Would you give me a hint about how to modify the above clases in order to parse the output of the del *.* ?
    No - but I will give you a hint about ProcessBuilder and how to develop software properly.
    Hint #1: Don't try to automate something that you don't know, or understand, how to do manually.
    a. Do you know how to execute 'del *.*' manually in a command window?
    b. Did you try that manually to see what happens?
    My guess is 'no'. If you had you would know that the response to a 'del *.*' command is going to be this:
    Are you sure (Y/N)?
    And your 'java class execution' doesn't finish because the 'del' command is waiting for you to answer that question.
    Hint #2: Don't try to use ProcessBuilder for an application that requires console input unless you first know how to provide that console input via your Java code.
    Your code will wait forever since it does NOT answer that question.
    Search the net and The Java Tutorials and  you can find examples of executing command line utilities. Then try those examples first and make sure that:
    1. They work for you
    2. You understand HOW they work
    Then you can modify those examples to do what you want to do.

  • Understand the output of explain plan

    I am trying to understand the output of explain plan. I have 2 plans below and don't understand it completely.
    In below SQL I would expect optimizer to fetch "ROWNUM < 500" first and then do the outer join. But below explain plan doesn't list it as No. 1. So I don't really understand how to intepret the sequence from the explain plan:
    select TASK0_.TASK_ID from
    (  select TASK0_.TASK_ID from
      ( select task0_.task_id  from task task0_) TASK0_ where ROWNUM < 500 ) TASK0_ 
    left outer join f_message_task task0_1_ on task0_.task_id=task0_1_.task_id
    left outer join b_a_task task0_2_ on task0_.task_id=task0_2_.task_id
    left outer join i_task task0_3_ on task0_.task_id=task0_3_.task_id
    left outer join o_task task0_4_ on task0_.task_id=task0_4_.task_id
    left outer join r_transmission_task task0_5_ on task0_.task_id=task0_5_.task_id
    left outer join s_error_task task0_6_ on task0_.task_id=task0_6_.task_id
    PLAN_TABLE_OUTPUT     
    Plan hash value: 707970537     
    | Id  | Operation                    | Name                     | Rows  | Bytes | Cost (%CPU)| Time     |     
    |   0 | SELECT STATEMENT             |                          |   499 | 19461 |  1042   (6)| 00:00:13 |     
    |*  1 |  HASH JOIN OUTER             |                          |   499 | 19461 |  1042   (6)| 00:00:13 |     
    |*  2 |   HASH JOIN OUTER            |                          |   499 | 16966 |   757   (6)| 00:00:10 |     
    |   3 |    NESTED LOOPS OUTER        |                          |   499 | 14471 |   589   (4)| 00:00:08 |     
    |   4 |     NESTED LOOPS OUTER       |                          |   499 | 12475 |   588   (4)| 00:00:08 |     
    |   5 |      NESTED LOOPS OUTER      |                          |   499 | 10479 |   588   (4)| 00:00:08 |     
    |   6 |       NESTED LOOPS OUTER     |                          |   499 |  8982 |   588   (4)| 00:00:08 |     
    |   7 |        VIEW                  |                          |   499 |  2495 |   588   (4)| 00:00:08 |     
    |*  8 |         COUNT STOPKEY        |                          |       |       |            |          |     
    |   9 |          INDEX FAST FULL SCAN| PK_TASK                  |   697K|  3403K|   588   (4)| 00:00:08 |     
    |* 10 |        INDEX UNIQUE SCAN     | PK_r_TRANSMISSION |     1 |    13 |     0   (0)| 00:00:01 |     
    |* 11 |       INDEX UNIQUE SCAN      | PK_b_a_TASK          |     1 |     3 |     0   (0)| 00:00:01 |     
    |* 12 |      INDEX UNIQUE SCAN       | PK_s_ERROR_TASK     |     1 |     4 |     0   (0)| 00:00:01 |     
    |* 13 |     INDEX UNIQUE SCAN        | PK_i_TASK    |     1 |     4 |     0   (0)| 00:00:01 |     
    |  14 |    INDEX FAST FULL SCAN      | PK_o_TASK           |   347K|  1695K|   161   (6)| 00:00:02 |     
    |  15 |   INDEX FAST FULL SCAN       | PK_f_MESSAGE        |   392K|  1917K|   276   (4)| 00:00:04 |     
    Predicate Information (identified by operation id):     
       1 - access("TASK0_"."TASK_ID"="TASK0_1_"."TASK_ID"(+))     
       2 - access("TASK0_"."TASK_ID"="TASK0_4_"."TASK_ID"(+))     
       8 - filter(ROWNUM<500)     
      10 - access("TASK0_"."TASK_ID"="TASK0_5_"."TASK_ID"(+))     
      11 - access("TASK0_"."TASK_ID"="TASK0_2_"."TASK_ID"(+))     
      12 - access("TASK0_"."TASK_ID"="TASK0_6_"."TASK_ID"(+))     
      13 - access("TASK0_"."TASK_ID"="TASK0_3_"."TASK_ID"(+))     
    In below SQL I expect rownum to be applied at the end but it gets applied first:
    select *  from (  select TASK0_.TASK_ID from ( select task0_.task_id  from task task0_ 
    left outer join f_message_task task0_1_ on task0_.task_id=task0_1_.task_id
    left outer join b_a_task task0_2_ on task0_.task_id=task0_2_.task_id
    left outer join i_task task0_3_ on task0_.task_id=task0_3_.task_id
    left outer join o_task task0_4_ on task0_.task_id=task0_4_.task_id
    left outer join r_t_task task0_5_ on task0_.task_id=task0_5_.task_id
    left outer join s_error_task task0_6_ on task0_.task_id=task0_6_.task_id
    ) TASK0_ where ROWNUM < 500 ) TASK0_;
    PLAN_TABLE_OUTPUT     
    Plan hash value: 673345378     
    | Id  | Operation                    | Name                     | Rows  | Bytes | Cost (%CPU)| Time     |     
    |   0 | SELECT STATEMENT             |                          |   499 |  6487 |   507   (1)| 00:00:07 |     
    |   1 |  VIEW                        |                          |   499 |  6487 |   507   (1)| 00:00:07 |     
    |*  2 |   COUNT STOPKEY              |                          |       |       |            |          |     
    |   3 |    NESTED LOOPS OUTER        |                          |   501 | 19539 |   507   (1)| 00:00:07 |     
    |   4 |     NESTED LOOPS OUTER       |                          |   501 | 17034 |     5  (20)| 00:00:01 |     
    |   5 |      NESTED LOOPS OUTER      |                          |   501 | 15030 |     5  (20)| 00:00:01 |     
    |   6 |       NESTED LOOPS OUTER     |                          |   501 | 13026 |     5  (20)| 00:00:01 |     
    |   7 |        NESTED LOOPS OUTER    |                          |   501 | 11523 |     5  (20)| 00:00:01 |     
    |   8 |         NESTED LOOPS OUTER   |                          |   501 |  5010 |     5  (20)| 00:00:01 |     
    |   9 |          INDEX FAST FULL SCAN| PK_TASK                  |   499 |  2495 |     2   (0)| 00:00:01 |     
    |* 10 |          INDEX UNIQUE SCAN   | PK_o_TASK           |     1 |     5 |     1   (0)| 00:00:01 |     
    |* 11 |         INDEX UNIQUE SCAN    | PK_r_T |     1 |    13 |     0   (0)| 00:00:01 |     
    |* 12 |        INDEX UNIQUE SCAN     | PK_b_a_TASK          |     1 |     3 |     0   (0)| 00:00:01 |     
    |* 13 |       INDEX UNIQUE SCAN      | PK_s_ERROR_TASK     |     1 |     4 |     0   (0)| 00:00:01 |     
    |* 14 |      INDEX UNIQUE SCAN       | PK_i_TASK    |     1 |     4 |     0   (0)| 00:00:01 |     
    |* 15 |     INDEX UNIQUE SCAN        | PK_f_MESSAGE        |     1 |     5 |     1   (0)| 00:00:01 |     
    Predicate Information (identified by operation id):     
       2 - filter(ROWNUM<500)     
      10 - access("TASK0_"."TASK_ID"="TASK0_4_"."TASK_ID"(+))     
      11 - access("TASK0_"."TASK_ID"="TASK0_5_"."TASK_ID"(+))     
      12 - access("TASK0_"."TASK_ID"="TASK0_2_"."TASK_ID"(+))     
      13 - access("TASK0_"."TASK_ID"="TASK0_6_"."TASK_ID"(+))     
      14 - access("TASK0_"."TASK_ID"="TASK0_3_"."TASK_ID"(+))     
      15 - access("TASK0_"."TASK_ID"="TASK0_1_"."TASK_ID"(+))Edited by: user628400 on Feb 20, 2009 12:14 PM
    Edited by: user628400 on Feb 20, 2009 12:15 PM

    Please read the FAQ: http://forums.oracle.com/forums/help.jspa
    And learn how to post code and explain plans using the tags.                                                                                                                                                                                                                                                                           

  • After I upgraded to Mavericks my Epson 5000V scanner is not working properly.  I can scan by going into Preference/PrintersScanners to operate the scanner, but I cannot find the output.

    After I upgraded to Mavericks my Epson 5000V scanner is not working properly.  I can scan by going into Preference/PrintersScanners to operate the scanner, but I cannot find the output.  I am trying to save the scan as a PDF in Documents.

    Have you installed Apple's latest Epson drivers?
    They are here:
    http://support.apple.com/kb/DL1398

  • I cannot get the Output Module to work. I was able to get the button to show up, but when I click on it, nothing happens. i need to export a PDF asap

    I cannot get the Output Module to work. I was able to get the button to show up, but when I click on it, nothing happens. i need to export a PDF asap. I am trying to export 33 PSD files in BRIDGE to a PDF like I used to do on my other computer with bridge.

    Let's start with the general things.
    When you have a problem with one particular site, a good "first thing to try" is clearing your Firefox cache and deleting your saved cookies for the site.
    (1) Bypass Firefox's Cache
    Use Ctrl+Shift+r to reload the page fresh from the server.
    Alternately, you also can clear Firefox's cache completely using:
    orange Firefox button (or Tools menu) > Options > Advanced
    On the Network mini-tab > Cached Web Content : "Clear Now"
    If you have a large hard drive, this might take a few minutes.
    (2) Remove the site's cookies (save any pending work first). While viewing a page on the site, try either:
    * right-click and choose View Page Info > Security > "View Cookies"
    * Alt+t (open the classic Tools menu) > Page Info > Security > "View Cookies"
    In the dialog that opens, you can remove the site's cookies individually.
    Then try reloading the page. Does that help?

  • Cannot get the output

    anybody know whats wrong with this code
    I cannot get the output it should be 9
    public class Arrays
    public Arrays()
    int a[] = { 7, 8, 9, 9, 8, 7 };
    System.out.println("\n\n\findMax():");
    System.out.println(findMax(a));
    public int findMax(int a[], int max)
    for (int i = 0; i < a.length; i++)
    if(a[i] > max)
    max = array;
    return max;

    public class Arrays {
         public static void main(String[] args) throws Exception{
              int a[] = { 7, 8, 9, 9, 8, 7 };
              System.out.println("FindMax():");
              System.out.println(findMax(a));
         public static int findMax(int a[]) throws Exception{
              int max = a[0];
              for (int i = 0; i < a.length; i++)
                   if (a[i] > max)
                        max = a;
              return max;

  • Cannot see the output file in my first project

    Hi,
    I follow the instructions of Exercise in Chapter 4 of CAP-0501 to make the project. I wonder why I cannot see the output file in 'C:\CAPExercises\0501\exercises\Active_Project\Output'.
    There are two things I would like you know.
    1. I do not have the file 'prjFileXferInput.xml', but find and copy a xml file. Is this a problem? Does CAPS have any special requirement on schema for the input file?
    2. Is '\' and '/' a problem for Java CAPS? I notice the book using 'C:/CAPExercises/0501/exercises/Active_Project/Output�, while it is 'C:\CAPExercises\0501\exercises\Active_Project\Output' on windows. I am working on a standalone Windows 2000 computer.
    By the way, can anyone give me a confirmation that '/' and '\' is not a problem for Java CAPS, as the server or application take care of it? Is it true?
    Thanks,

    I am answering my own question. The project works.

  • Can't understand the output of the exercise

    here is the problem:-
    An audio signal is sometimes stored as a list of int values. The values represent the intensity of the signal at successive time intervals. Of course, in a program the signal is represented with an array.
    Often a small amount of noise is included in the signal. Noise is usually small, momentary changes in the signal level. An example is the "static" that is heard in addition to the signal in AM radio.
    Smoothing a signal removes some of the noise and improves the perceptual quality of the signal. This exercise is to smooth the values in an integer array.
    Say that the original values are in the array "signal". Compute the smoothed array by doing this: Each value smooth[N] is the average of three values: signal[N-1], signal[N], and signal[N+1].
    For the first element of smooth, average the first two elements of signal. For the last element of smooth, average the last two elements of signal.
    here is the original data for the signal array.
    int[] signal  = {5, 5, 4, 5, 6, 6, 7, 6, 5, 4, 1, 4};i had to declare another array by the name of smooth.
    int[] smooth Now i am having a big problem. here is the output of the program from author point of view using the original data in signal array.
    C:\>java Smooth
    signal: 1 5 4 5 7 6 8 6 5 4 5 4
    smooth: 3 3 4 5 6 7 6 6 5 4 4 4
    C:\>i got completely lost. the original signal data is replaced by a new one but how ? if i can get a more detail explanation on this problem by anyone it would be great. so i thought to assign some duke dollars if i can understand the logic not trying to be greedy but to see who is a good teacher. thanks.
    once i get a good explanation i can go ahead and start coding and see if i can achieve this. i am pretty much sure it is a simple task but author made it looks like my worst nightmare.

    here is the problem:-
    An audio signal is sometimes stored as a list of int values. The values represent the intensity of the signal at successive time intervals. Of course, in a program the signal is represented with an array.
    Often a small amount of noise is included in the signal. Noise is usually small, momentary changes in the signal level. An example is the "static" that is heard in addition to the signal in AM radio.
    Smoothing a signal removes some of the noise and improves the perceptual quality of the signal. This exercise is to smooth the values in an integer array.
    Say that the original values are in the array "signal". Compute the smoothed array by doing this: Each value smooth[N] is the average of three values: signal[N-1], signal[N], and signal[N+1].
    For the first element of smooth, average the first two elements of signal. For the last element of smooth, average the last two elements of signal.
    here is the original data for the signal array.
    int[] signal  = {5, 5, 4, 5, 6, 6, 7, 6, 5, 4, 1, 4};i had to declare another array by the name of smooth.
    int[] smooth Now i am having a big problem. here is the output of the program from author point of view using the original data in signal array.
    C:\>java Smooth
    signal: 1 5 4 5 7 6 8 6 5 4 5 4
    smooth: 3 3 4 5 6 7 6 6 5 4 4 4
    C:\>i got completely lost. the original signal data is replaced by a new one but how ? if i can get a more detail explanation on this problem by anyone it would be great. so i thought to assign some duke dollars if i can understand the logic not trying to be greedy but to see who is a good teacher. thanks.
    once i get a good explanation i can go ahead and start coding and see if i can achieve this. i am pretty much sure it is a simple task but author made it looks like my worst nightmare.

  • Txt output problem,cannot order the output

    Hi,
    I'm working with forms and reports 6i, and I have a problem when generating the .txt output.
    My report consists in some columns (database-scalar) from the main query and in some columns(formula).
    What I'm trying to do is to mix the order of columns (database-scalar) and columns(formula),but
    I can't do it. The columns(formula) are always in the end of the output...
    I've put the right order in the report editor,but It only works to put the order of the columns (database-scalar) .
    Example
    query
    select a,b,c from..where...
    formula colum: desc_a,desc_b
    The desired output
    a desc_a b desc_b c
    The output I get
    a b c desc_a desc_b
    Thanks in advance

    Solved,reading anothers posts found the error.
    Just need to play with the "break order" and separating in groups the formula column and the database-scalar colum.

  • Cannot change the output medium for contract

    Hi Everyone,
    In the contract we have "Output" tab to change the output medium for the contract.
    So the issue is when I click on the change button and try to change e-mail address,I am not able to do that.
    The e-mail address is grayed out though I am in the change mode.
    This is happening for some contracts only.
    How should I change the e-mail address of the contract?
    Thanks & Regards,
    Khushbu.
    Edited by: Khushbu Brahmbhatt on Feb 25, 2011 9:01 PM

    Hi,
    Have a look at the foll thread for more pointers;
    Re: Change medium of output for Changed PO in SRM
    BR,
    Disha.
    Do reward points for useful answers.

  • Cannot understand the problem

    Hi frnds my name is raj , i am very new to OBIEE , i have been pracitcing it on my own and now i had few problems in understanding the errors .
    I built a physical layer with CHANNELS ,COSTS , COUNTRIES , PRODUCTS , SALES ,TIMES tables and SALES being the fact table ,,, I have physical joined every column except COST to sales .
    And in Bussiness layer i have created a new bussiness model and dragged all the tables from physical layer except COST table..
    In BMM layer , in Sales Table i have dragged a column named UNIT_COST from cost table in physcial layer and renamed it to unitcost , so the sales table in BMM layer has two sources i.e., SALES and COSTS .
    Now i applied aggergation sum rule on UNIT COST and dragged it to presentation layer ...
    When i opened the presentation server , and selected Product name from product table and Amount sold and Unitcost from sales table and when i click the results to view i have encountered with an error
    ODBC DRIVER RETURNED AN ERROR(SQLEXECDirectVV)
    the message says : UNIT_COST : invalid Identifier at OCI call .
    Please help me in understanding this error and kindly give me the solution for it
    thanks ...

    Hi,
    Firstly did you make a "view data" in the physical layer for the COSTS table. I am doubting that this table wasnot created in the db itself. Kindly check it and let us know if you have any issues
    Regards,
    BI Learner

  • I cannot understand the answers provided when I ask 'how to change a password for a website' in Firefox Options tab.

    The answers that your website have provided have not done me any good. I use a Master Password for Firefox. Now Firefox is not asking me if I want it to remember a certain password that I have entered for a website. In the 'Options' tab, I have told Firefox that I do not want to be tracked; that I don't want it to remember the history; and not to accept third-party cookies. What is it that I have to do in 'Options' so that Firefox remembers a new password (I have changed a password recently). I would really appreciate an actual answer, rather than a link to "some answers already posted".
    I'm using Firefox 33.1. Windows XP - Service Pack 3.
    Thank you.

    Are you saying that you changed your history setting here:
    "3-bar" menu button (or Tools menu) > Options > Privacy
    to "Firefox will: Never remember history"?
    This causes Firefox to always start up in a private browsing session. According to the help article "[[Usernames and passwords are not saved]]":
    <blockquote>If you use the Firefox Private Browsing feature, no passwords will be automatically filled in for your Private Browsing window or in permanent Private Browsing mode, and no new passwords will be saved.</blockquote>
    So hopefully that helps connect the dots.
    If you prefer to keep using automatic private browsing, you may need to use an add-on to manage your passwords instead of Firefox's built-in password manager.
    Or if you want to adjust other Firefox settings so that they are as close as possible to private browsing, we can suggest how to do that instead.

  • Firefox crashes - I need some help becaue I cannot understand the cause of my constant crashes...

    These are my last two crashes. I tried all that is commonly advised, but crashes are still frequent, about once or more every day.
    bp-dd8c6382-a254-4f16-aaf8-257152140313
    bp-98dc2419-5892-4cf8-89a7-ce3382140312
    Thanks

    hello mozi108, i'm locking this thread, because you already have created a similar question yesterday at https://support.mozilla.org/en-US/questions/989596. please put all new information about the crashing issue there instead of opening new questions for it, so that contributors can follow up on you more easily. thank you!

  • Firefox crashes - I need some help because I cannot understand the cause of my constant crashes...

    ''locking this thread as duplicate, please continue at [https://support.mozilla.org/en-US/questions/989596 /questions/989596]''
    AND AGAIN AND AGAIN...
    other two crashes in the last few minutes:
    bp-e23f3f47-df28-49aa-9117-870ee2140313
    bp-e656c64b-ddaa-4ca1-ab0a-2daea2140313

    hello mozi108, i'm locking this thread, because you already have created a similar question yesterday at https://support.mozilla.org/en-US/questions/989596. please put all new information about the crashing issue there instead of opening new questions for it, so that contributors can follow up on you more easily. thank you!

Maybe you are looking for

  • Data merge says source file is incompatible

    In InDesign 1 I knew that I had to convert Excel files to .csv files in order to merge the data into an idd file. Never understood why but it worked. When I do that with CS3 I get an error message saying that the file is empty or an incompatible file

  • How to change Number of test socket in Model option during run-time

    I wanna be able to change the the number of test sockets(in the Model Options menu) during runtime. I have overriden the Prebatch callback and used my own instead. I have a LabView program in my Prebatch where I would select the test script each time

  • Problems in createProcessInstance()

    I have problems in createProcessInstance with papi-ws in ALBPM 6. I am trying this papiServiceControl.processCreateInstance("Process", "BeginIn", null); But the exception below is returned. If I try to create an instance of process in version 5.7, it

  • Can no longer save edited images in version set with PS 10.

    I've been using PS 10 for many months and have been able to save my edited raw images as jpgs in version sets.  I can no longer do this.  The edited images save on the hard drive but not in the PS organizer...thank you for any help you can offer....

  • MS Word 2004 Macro viruses - how do I clean old files?

    Hi, We just got a new iMac and it's running Leopard. MS Office 2004 is installed and I transferred files from my old blueberry iMac about a week ago. Ever since, when I open a Word document from the old computer it asks if I would like to enable macr