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

How to define variables in java

WBOY
Release: 2023-05-06 11:49:06
forward
2865 people have browsed it

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;
Copy after login

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);
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template