所以我編寫了一個腳本,告訴腳本是否低於,高於或等於y值。不過,我希望能夠將我的價值觀放在一條線上,以便像3,6,7,9那樣。所以當你按下回車鍵時,就會顯示出答案。我的代碼:我該如何在一條線上而不是四條線上作出我的回答
package computing.line.linetest;
/** * Created by Jakob on 07-02-2015. */ public class LineTest {
public static void main (String[] arg) {
java.util.Scanner tastatur = new java.util.Scanner(System.in);
System.out.println("Indsæt a, x, b og y værdierne her og tryk retur");
int a, x, b, y;
a = tastatur.nextInt();
x = tastatur.nextInt();
b = tastatur.nextInt();
y = tastatur.nextInt();
System.out.println ("a er "+a+", x er "+x+", b er "+b+", y er "+y+"");
if (a * x + b == y) System.out.println("Linje");
else if (a * x + b > y) System.out.println("Under");
else System.out.println("Over");
} }
需要注意的是,所使用的語言是丹麥語而不是英語:) – 2015-02-07 16:00:13
除了最後一次打印之外,其他所有打印文檔中都使用'print'而不是'println'。或者在每行的末尾分別打印換行符。 – lurker 2015-02-07 16:04:22