#6078: 我不知道哪裡錯了 一直說我只有跑出一個答案 請JAVA高手指正


henry10423 (xiaoguang)


一直說我只有跑出一個答案

import java.util.Scanner;
public class scn
{
 public static void main(String[] args)
 {
  Scanner buf=new Scanner(System.in);
  int x,y;
  String s;
  s=buf.next();
  x=Integer.parseInt(s);
  s=buf.next();
  y=Integer.parseInt(s); 
  System.out.println(""+(x+y));
 }
}

#6079: Re:我不知道哪裡錯了 一直說我只有跑出一個答案 請JAVA高手指正


s11113151 (飛走跑跳動)


一直說我只有跑出一個答案

import java.util.Scanner;
public class scn
{
 public static void main(String[] args)
 {
  Scanner buf=new Scanner(System.in);
  int x,y;
  String s;
  s=buf.next();
  x=Integer.parseInt(s);
  s=buf.next(  y=Integer.parseInt(s); 
  System.out.println(""+(x+y));
 }
}

 

 

因為他測資通常不會只有一組 你看 A001的範例答案就應該知道 你缺少一個迴圈 如果這樣就可以了

import java.util.Scanner;
public class scn 
{
 public static void main(String[] args)
 {
  Scanner buf=new Scanner(System.in);

while(buf.hasNext()) {

  int x,y;

  String s;
  s=buf.next();
  x=Integer.parseInt(s);
  s=buf.next();
  y=Integer.parseInt(s);  
  System.out.println(""+(x+y));


 }
}