2014-03-31 103 views
0

我在eclipse中有這個java代碼。當我運行它時,我認爲我應該在Eclipse底部的控制檯中找回一些東西。不是這種情況。 eclipse底部的控制檯是空白的。未在Eclipse中打印到控制檯的Java代碼

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"); 


    } 

} 

} 
+1

何時'1'小於'0'? –

+1

明天1日是明天:) – JohnnyAW

回答

2

你有while循環設置爲x < 0,它應該是x > 0。你有它的方式,它永遠不會進入while循環

+0

真棒,這是...感謝幫助noobie出:) – PolarisUser

0

你的程序只打印到控制檯當x小於零,當x是2

X總有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"); 
} 

也許你想要的東西,像一個值這樣的:

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

您的條件不滿足,因此sysout語句不執行。請更改初始值x或條件,以便至少執行一次執行語句sysout

0

這兩個條件語句都不成立。 1不小於零或等於2.

2

您的狀態是錯誤的。它應該是while (x > 0)而不是while (x < 0)