我正在開發一個程序。我得到了我的最終結果,但不是所需的格式。我的要求是輸出應像被格式化[Z1,Z2 ...]我如何讓我的答案看起來像[z1,z2 ...]
public class Range {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
System.out.println("Please input your frist number.");
int input1 = red(console);
System.out.println("Please input your second number.");
int input2 = red(console);
printRange(input1, input2);
}
public static int red(Scanner console) {
int x = console.nextInt();
return x;
}
public static void printRange(int input1, int input2) {
if (input1 > input2) {
for (int Z = input1; Z >= input2; Z--) {
System.out.print("[" + Z + "]");
}
}
else if (input1 < input2) {
for (int Z = input1; Z <= input2; Z++) {
System.out.print("[" + Z + "]");
}
}
else {
System.out.print("[" + input1 + "]");
}
}
}
它是java,它不能運行使用片段。此外,我已經重申了它。 –
精彩的縮進,絕對不會讓你感到困惑;) –