原本想這樣寫:
import java.util.Scanner;
public class a005 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while (sc.hasNext())
{
int A = sc.nextInt();
int B = sc.nextInt();
int C = sc.nextInt();
int D = sc.nextInt();
if (B-A == D-C)
{
int X= B-A ;
String a = "%d %d %d %d %d \n";
System.out.printf(a, A, B, C, D, D+X);
}
else if(B/A == D/C)
{
int Y= D/C ;
String a = "%d %d %d %d %d \n";
System.out.printf(a, A, B, C, D, D*Y);
}
}
}
}
--------------------------------------------------------------
檢測RE(code:1)
換這樣寫
--------------------------------------------------------------
import java.util.Scanner;
public class a005 {
public static void main(String[] args)
{
int t;
Scanner sc = new Scanner(System.in);
t =sc.nextInt();
while (t != 0)
{
int A = sc.nextInt();
int B = sc.nextInt();
int C = sc.nextInt();
int D = sc.nextInt();
if (B-A == D-C)
{
int X= B-A ;
String a = "%d %d %d %d %d \n";
System.out.printf(a, A, B, C, D, D+X);
}
else
{
int Y= D/C ;
String a = "%d %d %d %d %d \n";
System.out.printf(a, A, B, C, D, D*Y);
}
}
}
}
-----------------------------------------------------------
也是RE
如下↓
-----------------------------------------------------------
import java.util.Scanner;
public class a005 {
public static void main(String[] args)
{
int t;
Scanner sc = new Scanner(System.in);
t =sc.nextInt();
while (t != 0)
{
int A = sc.nextInt();
int B = sc.nextInt();
int C = sc.nextInt();
int D = sc.nextInt();
if (B-A == D-C)
{
int X= B-A ;
String a = "%d %d %d %d %d \n";
System.out.printf(a, A, B, C, D, D+X);
}
else
{
int Y= D/C ;
String a = "%d %d %d %d %d \n";
System.out.printf(a, A, B, C, D, D*Y);
}
t--;
}
}
}
--------------------------------------------------------------------------
麻煩各位高手解惑了!
第一段程式碼:你少讀一個測資 t(然後要用 t 控制讀取測資的行數),後面再讀測資的時候就錯了。
第二、三段程式碼:沒有 t-- 會跑不出迴圈。
參考
JAVA
|
上面程式碼打不開我貼下面,不懂再看。
import java.util.Scanner; public class aa { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int t = sc.nextInt(); for (int i = 0; i < t; ++i) { int A = sc.nextInt(); int B = sc.nextInt(); int C = sc.nextInt(); int D = sc.nextInt(); if (B - A == D - C) { int X = B - A; String a = "%d %d %d %d %d \n"; System.out.printf(a, A, B, C, D, D + X); } else if (B / A == D / C) { int Y = D / C; String a = "%d %d %d %d %d \n"; System.out.printf(a, A, B, C, D, D * Y); } } } } }
第一段程式碼:你少讀一個測資 t(然後要用 t 控制讀取測資的行數),後面再讀測資的時候就錯了。
第二、三段程式碼:沒有 t-- 會跑不出迴圈。
參考
JAVA
|
上面程式碼打不開我貼下面,不懂再看。
import java.util.Scanner; public class aa { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int t = sc.nextInt(); for (int i = 0; i < t; ++i) { int A = sc.nextInt(); int B = sc.nextInt(); int C = sc.nextInt(); int D = sc.nextInt(); if (B - A == D - C) { int X = B - A; String a = "%d %d %d %d %d \n"; System.out.printf(a, A, B, C, D, D + X); } else if (B / A == D / C) { int Y = D / C; String a = "%d %d %d %d %d \n"; System.out.printf(a, A, B, C, D, D * Y); } } } } }
感謝解惑,剛出新手村感謝指導!