Curriculum
Course: Java Basic
Login

Curriculum

Java Basic

Java Home

0/1

Java Introduction

0/1

Java Get Started

0/1

Java Syntax

0/1

Java Comments

0/1

Java Type Casting

0/1

Java Operators

0/1

Java Booleans

0/1

Java Switch

0/1

Java Break / Continue

0/1

Java Errors and Exception

0/1
Text lesson

Multiple Variables

Declare Many Variables

You can declare multiple variables of the same type by listing them with commas in between.

Example

Instead of composing:

int x = 5;
int y = 6;
int z = 50;
System.out.println(x + y + z);

You can simply state:

int x = 5, y = 6, z = 50;
System.out.println(x + y + z);

One Value to Multiple Variables

In a single line, you can also assign a single value to multiple variables.

Example

int x, y, z;
x = y = z = 50;
System.out.println(x + y + z);