DAY 40: Array in Looping JAVA
In Java, an array is a data structure that stores a fixed-size, sequential collection of elements of the same data type. It is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created and remains fixed throughout its lifetime. Arrays are used to organize data efficiently and can be defined and initialized in various ways. Array - Group of similar datatypes Why do you use an array? Arrays are handy when you want to work with multiple values of the same data type. Instead of declaring individual variables for each value, you can group them together in an array, making your code more concise and easier to manage. Index / Subscript: 0 1 2 3 4 marks[0] = 90; marks[1] = 95; marks[2] = 100; marks[3] = 78; marks[4] = 94; System.out.println(marks[0]); System.out.println(marks[1]); System.out.println(marks[2]); System.out.println(marks[3]); System.out.println(marks[4]); int i =0; System.out.println(marks[i]); i = i+1; System.out.println(marks[i]); i = i+1; System.out.println(marks[i]); i = i+1; System.out.println(marks[i]); i = i+1; System.out.println(marks[i]); i = i+1; we add while loop int i =0; while(i

In Java, an array is a data structure that stores a fixed-size, sequential collection of elements of the same data type. It is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created and remains fixed throughout its lifetime. Arrays are used to organize data efficiently and can be defined and initialized in various ways.
Array - Group of similar datatypes
Why do you use an array?
Arrays are handy when you want to work with multiple values of the same data type. Instead of declaring individual variables for each value, you can group them together in an array, making your code more concise and easier to manage.
Index / Subscript: 0 1 2 3 4
marks[0] = 90;
marks[1] = 95;
marks[2] = 100;
marks[3] = 78;
marks[4] = 94;
System.out.println(marks[0]);
System.out.println(marks[1]);
System.out.println(marks[2]);
System.out.println(marks[3]);
System.out.println(marks[4]);
int i =0;
System.out.println(marks[i]); i = i+1;
System.out.println(marks[i]); i = i+1;
System.out.println(marks[i]); i = i+1;
System.out.println(marks[i]); i = i+1;
System.out.println(marks[i]); i = i+1;
we add while loop
int i =0;
while(i<5)
{
System.out.println(marks[i]);
i = i+1;
}
int i =0; //Initial Value Only Once
while(i for loop:
for(int i =0; i
Using Scanner
Scanner scanner = new Scanner(System.in);
System.out.println("Enter Mark:");
int mark1 = scanner.nextInt();
System.out.println("hi "+ mark1);
input()
scanner.next()
Scanner scans the next token from user (From console)
Scanner scanner = new Scanner(System.in);
System.out.println("Tell Me your name ");
String name = scanner.nextLine();
System.out.println("Welcome to Java "+ name);
Scanner scanner = new Scanner(System.in);
int mark1 = scanner.nextInt();
int mark2 = scanner.nextInt();
int mark3 = scanner.nextInt();
Scanner scanner = new Scanner(System.in);
int[] marks = new int[5];
marks[0] = scanner.nextInt();
marks[1]= scanner.nextInt();
marks[2] = scanner.nextInt();
marks[3]= scanner.nextInt();
marks[4] = scanner.nextInt();