数组类型
如果我们有一组类型相同的变量,例如,5位同学的成绩,可以这么写:
public class Main { public static void main(String[] args) { // 5位同学的成绩: int n1 = 68; int n2 = 79; int n3 = 91; int n4 = 85; int n5 = 62; } }
但其实没有必要定义5个int
变量。可以使用数组来表示“一组”int
类型。代码如下:
如果我们有一组类型相同的变量,例如,5位同学的成绩,可以这么写:
public class Main { public static void main(String[] args) { // 5位同学的成绩: int n1 = 68; int n2 = 79; int n3 = 91; int n4 = 85; int n5 = 62; } }
但其实没有必要定义5个int
变量。可以使用数组来表示“一组”int
类型。代码如下:
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。