/*
好东西也不能索取无度
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
//在此编写你的代码
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String str = reader.readLine();
String str1 = reader.readLine();
int num = Integer.parseInt(str1);
int a = 1;
while (a > 0){
System.out.println(str);
a++;
}
}
}
any one can tell me how to fix this problem? I can't figured it out by myself : (
need help guys!
已解决
评论 (7)
- 受欢迎
- 新
- 旧
你必须先登录才能发表评论
steven
10 十一月 2021, 06:25
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String n = reader.readLine();
int num = Integer.parseInt(reader.readLine());
while(num>0){
System.out.println(n);
num--;
}
0
furius72
22 十月 2022, 12:22
why "--" and no "++"?
0
Thomas
22 十月 2022, 21:33
cause it is a good way to approach this task (if you do not need num anymore) . Then you just count backwards from num to 0. You'll often see the decrement operator in the conditon like
If you need num later on again, then I'd use a for loop.
0
furius72
23 十月 2022, 17:51
👍
0
楊宗翰
6 七月 2020, 13:19
while(a > 0) {
a++
}
it will cause infinite loop
so , you should change a > 0 to a <=num (because you write a =1;).
and then when a = num the while loop will break.
0
Let's play video games
6 七月 2020, 17:39
Thanks a lot
0
楊宗翰
7 七月 2020, 06:53
you are welcome
0