- Java Programming for Beginners
- Mark Lassoff
- 290字
- 2021-07-02 15:22:44
Integer variables
To begin, let's create a new project in NetBeans. I'm going to call mine Variables, and this time we'll allow NetBeans to create the main class for us so that we can get to coding as quickly as possible. We need to delete all the comments that are created automatically by NetBeans when we create our new project, just to keep everything as readable as possible, then we'll be good to go:

The first computers were little more than calculators, and Java, of course, retains this functionality. For example, Java can evaluate 1+1, which will evaluate to 2, of course. However, Java is pretty complicated and designed to do a lot of different things, so we need to provide context to our commands. Here, we tell Java that we'd like it to print the result of 1+1:
package variables; public class Variables { public static void main(String[] args) { System.out.println(1+1); } }
Our preceding program will run as expected:

In addition to some others, Java can perform all the basic arithmetic operations. It can do addition, subtraction, multiplication (for which we use *, not X on our keyboard), and division. If we run the following program with the input of 2 and 3, we'll see four println() commands, all of which will give the proper result of the calculations. We can, of course, change these numbers to be any combination of numbers we see fit:
package variables; public class Variables { public static void main(String[] args) { System.out.println(2+3); System.out.println(2-3); System.out.println(2*3); System.out.println(2/3); } }
The following is the output of the preceding code:

Changing these lines manually is kind of a pain and quickly becomes infeasible if we're writing very complicated programs or dynamic programs that take user input.
- Learn to Create WordPress Themes by Building 5 Projects
- Vue.js入門與商城開發實戰
- Mastering Articulate Storyline
- Reactive Programming With Java 9
- ArcGIS By Example
- Learning JavaScript Data Structures and Algorithms
- OpenResty完全開發指南:構建百萬級別并發的Web應用
- Android項目實戰:手機安全衛士開發案例解析
- Web前端開發技術:HTML、CSS、JavaScript
- 少年小魚的魔法之旅:神奇的Python
- Python編程基礎與數據分析
- 數據庫基礎與應用實驗教程:Visual FoxPro 6.0
- Kubernetes進階實戰(第2版)
- 我跟爸爸學編程:從Python到C++
- jQuery權威指南(第2版)