How to Declare Many Variables of Same Type in Java


In this example we will show you how to declare many variables of the same type with a comma-separated list in Java.

Source Code

package com.beginner.examples;

public class MyClass {
  public static void main(String[] args) {
    int a = 15, b = 3, c = 7; // declare many variables
    System.out.println(a + b + c);
  }
}

Output:

25
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments