简体   繁体   中英

Java code not printing to console in Eclipse

I have this java code in eclipse. When I run it, I assume I should get something back in the console at the bottom of eclipse. This is not the case. The console at the bottom of eclipse is blank.

package com.veggiedogtreats.javacode;

public class doobeedoobeedo {

/**
 * @param args
 */
public static void main(String[] args) {
    int x = 1;
    while (x < 0) {
        System.out.println("Doo");
        System.out.println("Bee");
        x = x + 1;
    }
    if (x == 2 ) {
        System.out.print("Do");


    }

}

}

you have the while loop set to x < 0 , it should be x > 0 . The way you have it, it will never enter the while loop

Your while condition is wrong. it should read while ( x > 0 ) instead of while ( x < 0 )

Your program only prints to the console when x is less than zero and when x is 2.

x always has a value of 1.

int x = 1; // x is 1
while (x < 0) { // 1 is not less than zero, doesn't enter the loop
    System.out.println("Doo");
    System.out.println("Bee");
    x = x + 1;
}

if (x == 2 ) { // 1 is not two, doesn't enter the if
    System.out.print("Do");
}

Maybe you wanted something like this:

while (x < 0) { .... }

your conditions are not satisfied and hence the sysout statements are not executed. Either change the initial value of x or the conditions so that the sysout statements are executed atleast once.

Neither of the conditional statements are true. 1 is not less than zero or equal to 2.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM