v
How to solve this problem?I don't understand it's meaning.
正在讨论
评论 (10)
- 受欢迎
- 新
- 旧
你必须先登录才能发表评论
AE86
10 七月 2020, 15:55
import java.io.*;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws Exception {
//在此编写你的代码
Scanner sc =new Scanner(System.in);
int sum = 0;
while(true){
int number =sc.nextInt();
if(number==-1){
System.out.println(sum+number);
break;
}else{
sum =sum +number;
}
}
}
}
0
null
15 七月 2020, 16:37
Thank you very much!
0
zhao zhang
18 五月 2020, 00:21
import java.io.*;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws Exception {
//在此编写你的代码
int amount = 0;
while (true){
Scanner input = new Scanner(System.in);
int num = input.nextInt();
amount += num;
if (num == -1){
System.out.println(amount);
break;
}
}
}
}
0
ZhangSiYuan
17 五月 2020, 12:40
package zh.codegym.task.task04.task0442;
/*
相加
*/
import java.io.*;
public class Solution {
public static int a;
public static void main(String[] args) throws Exception {
//在此编写你的代码
while(true){
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
String s1 = read.readLine();
int n1 = Integer.parseInt(s1);
if(n1==-1){
a = a + n1;
System.out.println(a);
break;
}else{
a = a + n1;
}
}
}
}
0
ZhangSiYuan
17 五月 2020, 12:41
结果正确,显示结果错误,这是不是验证出错了
0
ZhangSiYuan
17 五月 2020, 12:47
int a 声明全局变量验证通过不了。
0
乐是
5 五月 2020, 13:21
package zh.codegym.task.task04.task0442;
/*
相加
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//在此编写你的代码
int sum =0;
while(true){
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
String num = buffer.readLine();
int a = Integer.parseInt(num);
if(a==-1)
{
sum +=a;
System.out.println(sum);
break;}
else
{
sum+=a;
}
}
}
}
0
Guadalupe Gagnon
31 三月 2020, 15:01
You need to attach the solution or we can't help you
0
王宪宇
2 四月 2020, 14:20
0
乐是
5 五月 2020, 13:22
你的是死循环
0