在for循环,什么是(INT I:高)做的,其中个头一个int数组 [英] in a for-loop, what does the (int i : tall) do, where tall is an array of int
本文介绍了在for循环,什么是(INT I:高)做的,其中个头一个int数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
作为标题说,我被一些人放倒,如果我想打印的一切的总和数字数组,我应该使用上述参数for循环(code将跟随如果需要进一步的解释)。但是,什么是该做什么确切的definiton?本:双组分我的意思。是吗;每一个数字我在数组中高?
进口的java.util。*;类Uke36 {
公共静态无效的主要(字串[] args){ 扫描仪输入=新的扫描仪(System.in);
INT []高大=新INT [5]; 的for(int i = 0; I< = 4;我++){
的System.out.println(Vennligst oppgi DET+第(i + 1)+tallet:);
高大的[I] = input.nextInt();
}
INT总和= 0;
对于(INT I:高){
总和+ =;
}
}
}
解决方案
这是如何的for-each在Java中psented
回路重新$ P $。
的for(int我:高){
总和+ =;
}
基本上,在这里它说:
对于每一个整数i在数组称为尾...
As the header says, I was tipped by some people that if I wanted to print the sum of everything in an array of numbers, I should use the above-mentioned parameter for a for-loop (code will follow if further explanation is needed). But what is the exact definiton of what that does? The :-part I mean. Is it; for every number i in the array tall?
import java.util.*;
class Uke36{
public static void main(String[]args){
Scanner input=new Scanner(System.in);
int[] tall=new int[5];
for (int i=0; i<=4; i++){
System.out.println("Vennligst oppgi det " + (i+1) + ". tallet: ");
tall[i]=input.nextInt();
}
int sum = 0;
for(int i : tall){
sum+=;
}
}
}
解决方案
This is how for-each
loops are represented in Java.
for(int i : tall){
sum+=;
}
Basically, here it says:
For each integer i in the array called tail ...
这篇关于在for循环,什么是(INT I:高)做的,其中个头一个int数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文