You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: chapter-02-simple-calculations.md
+15-15Lines changed: 15 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,7 @@ In the example above, in the variable **`num`** of integer type **`int`**, we wi
48
48
49
49
Java is **highly typed language** this means that the variables have type determine at compile-time and can not change at the execution time (as it is in dynamic languages such as JavaScript and Python). In the example above `scanner` is from type `java.util.Scanner` (scanning text reader) and the variable `num` is from type `int` (integer number).
50
50
51
-
### Example: Calculating a square area with side **а**
51
+
### Example: Calculating the area of the square with side **а**
52
52
53
53
As an example, let us look at a program. The task is to calculate the area of a square by a given side's length read as input from the console. The sample source code of the program is below. The code **reads an integer** as input from the console, **multiply it** by itself (squares it), and as output **prints the result** from the multiplication. Save the code in a file with the name SquareArea.java, or else you will have a compile-time error:
54
54
@@ -383,7 +383,7 @@ Scanner scanner = new Scanner(System.in);
383
383
System.out.print("Enter circle radius. r = ");
384
384
double r =Double.parseDouble(scanner.nextLine());
385
385
System.out.println("Area = "+Math.PI* r * r);
386
-
// Math.PI - вградена в Java константа за π
386
+
// Math.PI - built-in function in Java
387
387
System.out.println("Perimeter = "+2*Math.PI* r);
388
388
```
389
389
Let’s test the program with **radius `r = 10`**:
@@ -442,11 +442,11 @@ To summarize what have we learned in this chapter of the book:
442
442
443
443
## Exercises: Simple calculations
444
444
445
-
Let's solidify what we learned in this chapter with some exercises.
445
+
To consolidate our knowledge of simple calculations, let's solve several exercises.
446
446
447
-
### Blank IntelliJ IDEA Solution (Project)
447
+
### Blank IntelliJ IDEA solution (Project)
448
448
449
-
We start by creating an empty solution **(Project)** in IntelliJ IDEA. The solutions (project) in IntelliJ IDEA combine **a group of tasks**. This opportunity is **very convenient** when we want to **work on a few projects** and switch quickly between them or we want to **unite logically a few interconnected projects**.
449
+
We start by creating an empty solution **(Project)** in IntelliJ IDEA. The solutions (project) in IntelliJ IDEA combine **a group of tasks**. This opportunity is **very convenient** when we want to **work on a few projects** and switch quickly between them or we want to **consolidate logically a few interconnected projects**.
450
450
451
451
In the current practical exercise we will use a **Project with a couple of tasks (Java classes)** to organize the solutions of the tasks from the exercises – every task in a separate Java class and all of them in a common project.
452
452
@@ -461,7 +461,7 @@ Select from the dialog window [**Java**], in the field Project SDK we specify wh
Give an appropriate name for the project, for example "SimpleCalculations" and also where to be stored our project, after that we click [**Finish**]:
464
+
Give an appropriate name for the project, for example "SimpleCalculations" and also where to be stored our project, and after that we click [**Finish**]:
@@ -471,29 +471,29 @@ Now we have **empty IntelliJ IDEA Project** (without any Java classes in it whic
471
471
472
472
The purpose of this project is to add in it **`.java` class per problem** from the exercises.
473
473
474
-
### Problem: Calculating Square Area
474
+
### Exercise: Calculating the area of the square
475
475
476
-
The first exercise from this topic is the following: write a console program that **inputs an integer `a` and calculates the area** of a square with side **`a`**. The task is trivial and easy: **input a number** from the console, **multiply it by itself** and **print the obtained result** on the console.
476
+
The first task from this topic is the following: write a console program that read as **input data an integer `a` and calculates the area** of a square with side **`a`**. The task is trivial and easy: read as **input data a number** from the console, then **multiply it by itself** and **print the obtained result** as an output on the console.
477
477
478
-
#### Hints and Guidelines
478
+
#### Hints and guidelines
479
479
480
-
We create **new Java class** in existing IntelliJ IDEA project. On the **src** folder right-click with the mouse. Choose [**New**] → [**Java Class**]:
480
+
We create a **new Java class** in the existing IntelliJ IDEA project. On the **src** folder, right-click with the mouse. Choose [**New**] → [**Java Class**]:
We already have a Project with Java class in it. What remains is to write the **code for solving this problem**. For this purpose, we write in our Java class `Main` method(as it is shown on the picture) and we go to the main method's body **`Main(string[] args)`**, and write the following code between the opening and closing curly brackets:
488
+
We already have a Project with Java class in it. What remains is to write the **code for solving this problem**. For this purpose, we write in our Java class a `Main` method(as in the picture below). In the body of the `Main` method**`Main(string[] args)`** we write the following code between the opening and closing curly brackets:
The code inputs an integer through **`a= Integer.parseInt(scanner.nextLine())`**, afterwards it calculates **`area = a * a`** and finally prints the value of the variable **`area`**. **We start** the program with [**Ctrl+Shft+F10**] and we **test** it with different input values:
492
+
As we can see in the code above, we read as input data an integer and assign it to a variable **`a`** (line **`int a = Integer.parseInt(scanner.nextLine())`**), afterwards we calculate the area (line **`int area = a * a`**) and finally prints the value of the variable **`area`** on the console. **We start** the program with [**Ctrl+Shft+F10**] and we **test** it with different input values:
Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/649#0](https://judge.softuni.bg/Contests/Practice/Index/649#0). You have to get 100 points (completely correct solution):
499
499
@@ -502,7 +502,7 @@ Test your solution here: [https://judge.softuni.bg/Contests/Practice/Index/649#0
Write a program that **reads a number from the console** (not necessarily an integer) and converts the number from **inches to centimeters.** For this purpose **it multiplies the inches by 2.54** (because one inch = 2.54 centimeters).
0 commit comments