English

Explain the usage of the following special symbol in Java: [](brackets)

Advertisements

Question

Explain the usage of the following special symbol in Java:

[](brackets)

Explain
Advertisements

Solution

The square brackets [] are used in Java to declare arrays and access their elements. They indicate that a variable can store multiple values of the same data type. Square brackets are also used with an index number to access or modify a particular element of an array. Array indexing in Java starts from 0.

Example:

int marks[] = {10, 20, 30, 40};
System.out.println(marks[0]);

Output:

10
shaalaa.com
  Is there an error in this question or solution?
Chapter 6: Variables and Expressions - EXERCISE [Page 135]

APPEARS IN

Dheeraj Mehrotra Computer Science [English] Class 12
Chapter 6 Variables and Expressions
EXERCISE | Q 60. (e) | Page 135
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×