英文:
Go through for loop specific number of times like range() in python
问题
我终于开始学习 Java 了,在不断地将它与 Python 精英主义进行比较哈哈开玩笑。开玩笑放一边,我期待着用 Java 编码,并且已经在享受其中的乐趣。
在解决问题时,我似乎找不到一个简单的解决方案。基本上,我想创建一个类似于 Python 中的 for 循环,可以重复特定次数,就像这样:
for (int i = 0; i < 10; i++) {
System.out.println("You win");
}
但当然是针对 Java 的。
经过在互联网上搜索后,我尝试了以下代码:
for (int i : new Range(10)) {
System.out.println("You win");
}
但是上述代码给我报错:
Range cannot be resolved to a type
希望能得到帮助。
英文:
I finally got around to learning java after continuously bashing it as a python elitist lol.
All jokes aside, I'm looking forward to playing with java and already having some fun with it.
I couldn't seem to find a simple solution for my problem. Basically, I want to make a for loop that will repeat itself a specific amount of times similar to this as in python:
for i in range(10):
Print("You win")
but for java of course.
I tried the following after some digging on the internet:
for (int i : new Range(10)) {
System.out.println("You win");
}
The following code gave me an error saying:
Range cannot be resolved to a type
Any help would be appreciated.
答案1
得分: 1
一个简单的for循环就可以解决问题:
for(int i = 0 ; i < 10; i++){
System.out.println("你赢了");
}
英文:
A simple for loop would do the trick:
for(int i = 0 ; i < 10; i++){
System.out.println("you win");
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论