简体   繁体   English

Output 未在此 JAVA 代码中显示第二个数组

[英]Output is not showing second array in this JAVA code

public class Main {
   public static void main() 
   Int[] Arr = new int [5];
   Arr[0] = 1;
   Arr[1] = 2;
   Arr[2] = 6;
   Arr[3] = 11;
   Arr[4] = 8;{
   System.out.println(Arr[2])
}

I need to print number in the second array.我需要在第二个数组中打印数字。

I need to print number in the second array.我需要在第二个数组中打印数字。

lets start with the basics coz we are here to help and you are willing to learn!!让我们从基础开始,因为我们在这里为您提供帮助,而且您愿意学习!!

you have defined only one array... int[] Arr so there is no 2nd array to be printed..您只定义了一个数组... int[] Arr所以没有要打印的第二个数组..

arrays in java are zero index , means the 2nd element in your array is located at the slot under the index number 1 java 中的 arrays 是zero index ,这意味着数组中的第二个元素位于索引号 1 下的插槽中

in your case Arr[1] is the 2nd element tho在您的情况下, Arr[1] 是第二个元素

in java there is no such primitive named Int so you can not declare在 java 中没有名为Int的原语,因此您不能声明

Int foo = 0;

must be一定是

int foo = 0; //small **i**

the entry point of any java application is the main method with the signature任何 java 应用程序的入口点是带有签名的 main 方法

 public static void main(String[] args) 

not不是

 public static void main() 

last but not least: we declare variables in java camel-case means, beginning with small character最后但同样重要的是:我们在 java 中声明变量,驼峰式表示,以小字符开头

therefore所以

int[] Arr = new int [5];

should be actually实际上应该是

int[] arr = new int[5];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM