Home >Java >javaTutorial >How to define variables in java

How to define variables in java

WBOY
WBOYforward
2023-05-06 11:49:062900browse

1. If you want to use Java to represent a number: 100. Then you need to assign it to a variable and define the data type and name for it, similar to this:

Define variables

int number = 100;

2. You can also temporarily not initialize it, and then assign a value to the variable when certain combined calculations are needed:

Declare the variable without initializing the value

int sum;
sum = 1+1;
System.out.println(sum);

Local declaration If a variable is not assigned a value, it cannot be used directly.

The above is the detailed content of How to define variables in java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete