太感人终于把1001做对了,一开始没有看清题目要求。产生各种各样的错误,最后又有编译错误。在Pat中Java的类名必须为
Public class Main
接下来po上代码,开心的像100斤的胖子
import java.util.*;
public class Practice1001 {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
String number = sc.nextLine();
String[] _number = number.split(" ");
long a = Long.parseLong(_number[0]);
long b = Long.parseLong(_number[1]);
int i,start;
String sub;
long result = a+b;
String result_s = result +"";
StringBuilder s = new StringBuilder();
if(result <0){
s.insert(0,"-");
start = 1;
}
else{
start = 0;
}
for(i = result_s.length(); i -start > 3;i-=3){
sub = result_s.substring(i-3,i);
s.insert(start,sub);
s.insert(start,",");
}
sub = result_s.substring(start,i);
s.insert(start,sub);
System.out.println(s);
}
}
网友评论