Loading...
「ツール」は右上に移動しました。
利用したサーバー: wtserver3
0いいね 23回再生

SINGLE DIMENSIONAL ARRAY WITH SCANNER CLASS || JAVA PROGRAMING||

#programming
Example:
package onedimensionalarray;
//One Dimensional Array Java Program using Scanner Class
import java.util.Scanner;

public class OneDimensionalScanner {
public static void main(String[] args) {
int len;
Scanner sc=new Scanner(System.in);
len=sc.nextInt();
int a[]=new int[len]; //declaration
for(int i=0; i(lessthan)=len; i++) {
a[i]=sc.nextInt();
}
System.out.println("Elements in Array are:\n");
for(int i=0; i(lessthan)=len; i++) {
System.out.println(a[i]+" ");
}

}

}

Accessing elements of an array in Java

We can access the elements of an array using the index number. Here is the syntax for accessing elements of an array.
//access array elements
Array[index]
Example: Access Array Elements
package onedimensionalarray;

//Accessing Array Elements
public class AccessingElements {
public static void main(String[] args) {
//create an array
int[] age= {12,4,6,8,9};
//access each array elements
System.out.println("Accessing Elements of Array");
System.out.println("First Element:"+age[0]);
System.out.println("Second Element:"+age[1]);
System.out.println("Third Element:"+age[2]);
System.out.println("Fourth Element:"+age[3]);
System.out.println("Fifth Element:"+age[4]);
}

}

#Coding
#DeveloperLife
#TechTalk
#codesnippet
#SoftwareDevelopment
#WebDevelopment
#CodeNewbie
#ProgrammingTips
#LearnToCode

コメント