Define more than one variable with comma

To declare more than one variable of the specified type, you may use a comma-separated list of variable names.


public class Example {
  public static void main(String args[]) {
    int num, num2;
    num = 100; // assigns num the value 100
    num2 = 200;
    System.out.println("This is num: " + num);
    System.out.println("This is num2: " + num2);

  }
}

When the program is run, the following output is displayed:


This is num: 100
This is num2: 200
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.