灯草


私信TA

用户名:dc7788

访问量:372

签 名:

等  级
排  名 31435
经  验 436
参赛次数 0
文章发表 2
年  龄 0
在职情况 学生
学  校 广东工业大学
专  业 电子信息

  自我简介:

TA的其他文章

解题思路:注意事项:第一次直接拿整数int去接收输入的发现不行,之后才发现是接收2^32,而int是-2^31到2^31-1;所以输入的应该为字符串

参考代码:

import java.util.Scanner;


public class Main {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

while (scanner.hasNext()) {

String str =scanner.nextLine();

int sum=0;

for(int i=0;i<str.length();i++){

    sum+=str.charAt(i)-'0';

}

System.out.println(sum);

}

}

}


 

0.0分

0 人评分

  评论区