#3820: 請問為什麼RE?


tinawang (Tina)


import java.util.Scanner;

public class C022 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
         int t = in.nextInt();
         for(int r = 0; r < t; r++){
           int a = in.nextInt();
           int b = in.nextInt();
           int c = 0;
          if(a == b){
            if((a%2)==1)
             System.out.println("case "+ (r+1) + ": " + a);
           else
             System.out.println("case "+ (r+1) + ": 0");
           }
           else{
            while(a <= b){
             if((a%2)==1){
              c += a;
              a += 2;
             }
             else{
              a++;
               c += a;
              a += 2;
             }
            }
            System.out.println("case "+ (r+1) + ": " +c);
           }
           }
        }
    }
}
 請問一下 為什麼會RE?  在讀取格式上是有漏掉什麼嗎?
#4124: Re:請問為什麼RE?


tomoyaken14 (歐練)


import java.util.Scanner;

public class C022 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
         int t = in.nextInt();
         for(int r = 0; r < t; r++){
           int a = in.nextInt();
           int b = in.nextInt();
           int c = 0;
          if(a == b){
            if((a%2)==1)
             System.out.println("case "+ (r+1) + ": " + a);
           else
             System.out.println("case "+ (r+1) + ": 0");
           }
           else{
            while(a <= b){
             if((a%2)==1){
              c += a;
              a += 2;
             }
             else{
              a++;
               c += a;
              a += 2;
             }
            }
            System.out.println("case "+ (r+1) + ": " +c);
           }
           }
        }
    }
}
 請問一下 為什麼會RE?  在讀取格式上是有漏掉什麼嗎?

我也是用JAVA寫...

 也一直RE...

有神人用JAVA寫過的嗎?0.0

#4125: Re:請問為什麼RE?


tomoyaken14 (歐練)


import java.util.Scanner;

public class C022 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
         int t = in.nextInt();
         for(int r = 0; r < t; r++){
           int a = in.nextInt();
           int b = in.nextInt();
           int c = 0;
          if(a == b){
            if((a%2)==1)
             System.out.println("case "+ (r+1) + ": " + a);
           else
             System.out.println("case "+ (r+1) + ": 0");
           }
           else{
            while(a <= b){
             if((a%2)==1){
              c += a;
              a += 2;
             }
             else{
              a++;
               c += a;
              a += 2;
             }
            }
            System.out.println("case "+ (r+1) + ": " +c);
           }
           }
        }
    }
}
 請問一下 為什麼會RE?  在讀取格式上是有漏掉什麼嗎?

我也是用JAVA寫...

 也一直RE...

有神人用JAVA寫過的嗎?0.0



執行時發生錯誤(code:1)!!
Exception in thread "main" java.util.NoSuchElementException
 at java.util.Scanner.throwFor(Scanner.java:817)
 at java.util.Scanner.next(Scanner.java:1431)
 at java.util.Scanner.nextInt(Scanner.java:2040)
 at java.util.Scanner.nextInt(Scanner.java:2000)
 at code_548001.main(code_548001.java:11)
#4126: Re:請問為什麼RE?


tomoyaken14 (歐練)


import java.util.Scanner;

public class C022 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
         int t = in.nextInt();
         for(int r = 0; r < t; r++){
           int a = in.nextInt();
           int b = in.nextInt();
           int c = 0;
          if(a == b){
            if((a%2)==1)
             System.out.println("case "+ (r+1) + ": " + a);
           else
             System.out.println("case "+ (r+1) + ": 0");
           }
           else{
            while(a <= b){
             if((a%2)==1){
              c += a;
              a += 2;
             }
             else{
              a++;
               c += a;
              a += 2;
             }
            }
            System.out.println("case "+ (r+1) + ": " +c);
           }
           }
        }
    }
}
 請問一下 為什麼會RE?  在讀取格式上是有漏掉什麼嗎?

我也是用JAVA寫...

 也一直RE...

有神人用JAVA寫過的嗎?0.0



執行時發生錯誤(code:1)!!
Exception in thread "main" java.util.NoSuchElementException
 at java.util.Scanner.throwFor(Scanner.java:817)
 at java.util.Scanner.next(Scanner.java:1431)
 at java.util.Scanner.nextInt(Scanner.java:2040)
 at java.util.Scanner.nextInt(Scanner.java:2000)
 at code_548001.main(code_548001.java:11)


AC了...

把while拿掉試試看...