Skip to content

Commit cee0cf7

Browse files
committed
Chapter 5.1 - Grammarly + Upper Letter Titles
1 parent 9387916 commit cee0cf7

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

chapter-05-loops.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Chapter 5.1. Repetitions (Loops)
22

3-
In the present chapter, we will get familiar with how to **repeat blocks of commands**, known in software development as "**loops**". We will write several loops using the **`for`** operator in its simplest form. Finally, we will solve some practical problems that require repeating series of actions, using loops.
3+
In the present chapter, we will get familiar with how to **repeat blocks of commands**, known in software development as "**loops**". We will write several loops using the **`for`** operator in its simplest form. Finally, we will solve some practical problems that require repeating a series of actions, using loops.
44

55
## Video
66

@@ -44,13 +44,13 @@ Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/655#
4444

4545
You should get **100 points** (fully accurate solution).
4646

47-
## Code Snippet for **`for`** loop in IntelliJ IDEA
47+
## Code Snippet for The **`for`** Loop in IntelliJ IDEA
4848

49-
In software development, we regularly need to write loops dozens of times a day. That is why in most integrated development environments (IDE), there are **code snippets** for writing loops. One such example is the **snippet for `for` loop in IntelliJ IDEA**. Write down **`fori`** in the Java code editor in IntelliJ IDEA and **press** [**Enter**]. IntelliJ IDEA will run the snippet, and you will see the entire **`for` loop** written down. All you have to do now is to add the values.
49+
In software development, we regularly need to write loops dozens of times a day. That is why in most integrated development environments (IDE), there are **code snippets** for writing loops. One such example is the **snippet for the `for` loop in IntelliJ IDEA**. Write down **`fori`** in the Java code editor in IntelliJ IDEA and **press** [**Enter**]. IntelliJ IDEA will run the snippet, and you will see the entire **`for` loop** written down. All you have to do now is to add the values.
5050

5151
![](assets/chapter-5-1-images/00.For-loop-code-snippet-01.png)
5252

53-
**Try it yourself** in order to master using the code snippet for **`for` loop** in IntelliJ IDEA.
53+
**Try it yourself** to master using the code snippet for the **`for` loop** in IntelliJ IDEA.
5454

5555
### Problem: Numbers Ending in 7
5656

@@ -119,7 +119,7 @@ Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/655#
119119

120120
### Problem: Max Number
121121

122-
Write a program that inputs **n integers** (**n** > 0) and finds the **the Max Number** (the largest number) among them. The first line of the input specifies the number of integers **n**. The following **`n`** lines consist of one integer. Examples:
122+
Write a program that inputs **n integers** (**n** > 0) and finds the **Max Number** (the largest number) among them. The first line of the input specifies the number of integers **n**. The following **`n`** lines consist of one integer. Examples:
123123

124124
#### Sample Input and Output
125125

@@ -204,15 +204,15 @@ We input the numbers one by one and calculate the two **sums** (the numbers on *
204204

205205
![](assets/chapter-5-1-images/08.Odd-even-sum-01.png)
206206

207-
**`+=`** is **combined assigment operator** that is used frequently. It adds the value of the right to the left operand and then assignes the result to the left operand.
207+
**`+=`** is a **combined assignment operator** that is used frequently. It adds the value of the right to the left operand and then assigns the result to the left operand.
208208
**C += A** is equivalent to **C = C + A**.
209209

210210
#### Testing in The Judge System
211211

212212
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/655#7](https://judge.softuni.org/Contests/Practice/Index/655#7).
213213

214214

215-
### Exapmle: Vowels Sum
215+
### Problem: Vowels Sum
216216

217217
Write a program that inputs **text** (string), calculates and prints **the sum of the values of vowels** according to the table below:
218218

@@ -229,7 +229,7 @@ Write a program that inputs **text** (string), calculates and prints **the sum o
229229

230230
#### Hints and Guidelines
231231

232-
We read the input text **`s`**, after that we null the sum and run a loop from **0** to **`s.length() - 1`** (text lenght -1). We check every letter **`s.charAt(i)`** if it is a vowel and add its value to the sum.
232+
We read the input text **`s`**, after that, we null the sum and run a loop from **0** to **`s.length() - 1`** (text length -1). We check every letter **`s.charAt(i)`** if it is a vowel and add its value to the sum.
233233

234234
![](assets/chapter-5-1-images/09.Vowels-sum-01.png)
235235

@@ -244,15 +244,15 @@ We can repeat a block of code using **`for` loop**:
244244

245245
![](assets/chapter-5-1-images/00.For-loop-01.png)
246246

247-
We can read series of **`n`** numbers from the console:
247+
We can read a series of **`n`** numbers from the console:
248248

249249
![](assets/chapter-5-1-images/00.For-loop-03.png)
250250

251-
## Problems Repetitions (Loops)
251+
## Problems: Loops
252252

253253
After we had acquainted with the loops, it is time to **solidify what we have learned by practicing it**, by writing a lot of code. Let us solve some problems for exercise.
254254

255-
### Creating new project in IntelliJ IDEA
255+
### Creating a new project in IntelliJ IDEA
256256

257257
We start by creating a new project in IntelliJ IDEA to better organize our solutions for the exercise. For each problem, we will create a separate class.
258258

@@ -272,19 +272,19 @@ We name the project (Project name:) **Loops** and select the directory where the
272272

273273
![](assets/chapter-5-1-images/10.New-project-04.png)
274274

275-
In the next window, we click on the **[OK]** button to create **Project location** if the directory doesn't exist.
275+
In the next window, we click on the **[OK]** button to create a **Project location** if the directory doesn't exist.
276276

277277
![](assets/chapter-5-1-images/10.New-project-05.png)
278278

279279
We created a new project. If we click on the triangle in front of **Loops** on the left side of the window, the structure of the project itself will open.
280280

281281
![](assets/chapter-5-1-images/10.New-project-06.png)
282282

283-
To create **Package** in our project, which contains all the classes with the solutions from the exercise, right-click with the mouse on **src**, then select **New** -> **Package** and name it **problems** (with a small first letter).
283+
To create a **Package** in our project, which contains all the classes with the solutions from the exercise, right-click with the mouse on **src**, then select **New** -> **Package** and name it **problems** (with a small first letter).
284284

285285
![](assets/chapter-5-1-images/10.New-project-07.png)
286286

287-
To create new class for the first problem, right-click with the mouse on **problems**, select **New** -> **Java Class** and name it **problem_01** (with a capital letter).
287+
To create a new class for the first problem, right-click with the mouse on **problems**, select **New** -> **Java Class**, and name it **problem_01** (with a capital letter).
288288

289289
![](assets/chapter-5-1-images/10.New-project-08.png)
290290

@@ -296,7 +296,7 @@ After these changes, the structure of the project should look like this:
296296

297297
For each subsequent exercise, we will create a new class in the way described above.
298298

299-
### Problem: An element equal to the sum of the others
299+
### Problem: Half Sum Element
300300

301301
Write a program that inputs **n integers** and checks if there is a number among them that is equal to the sum of all others. If there is such an element, print **"Yes" + its value**. Otherwise, print **"No" + the difference between the largest element and the sum of the rest**, as an absolute value.
302302

@@ -321,7 +321,7 @@ Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/655#
321321

322322
### Problem: Odd \/ Even position
323323

324-
Write a program that reads **n numbers** and calculates **the sum**, the **min** and **max** values of the numbers on **even** and **odd** positions (counted from 1). If there is no min / max element, print **"No"**.
324+
Write a program that reads **n numbers** and calculates **the sum**, the **min**, and **max** values of the numbers on **even** and **odd** positions (counted from 1). If there is no min / max element, print **"No"**.
325325

326326
#### Sample Input and Output
327327

@@ -336,7 +336,7 @@ Write a program that reads **n numbers** and calculates **the sum**, the **min**
336336

337337
The problem combines several previous problems: finding the **min**, **max**, and the **sum**, as well as processing elements on **even and odd positions**. Check your solutions to the previous problems again.
338338

339-
In the current problem, it is better to work with **fractions** (not integers). The sum, the min, and the max value will also be fractions. We have to use **neutral starting value** in finding the min / max value, for example **1000000000.0** and **-1000000000.0**. If the result is equal to the neutral value, we will print **“No”**.
339+
In the current problem, it is better to work with **fractions** (not integers). The sum, the min, and the max value will also be fractions. We have to use a **neutral starting value** in finding the min / max value, for example **10000.0** and **-10000.0**. If the result is equal to the neutral value, we will print **“No”**.
340340

341341
#### Testing in The Judge System
342342

@@ -364,16 +364,16 @@ The input consists of number **n**, followed by **2\*n integers**, one per line.
364364

365365
#### Hints and Guidelines
366366

367-
We read the input numbers **in pairs**. For each pair, we calculate the **sum**. While reading the input pairs, for each pair, except the first one, we have to calculate **the difference with the previous one**. To do that, we need to store the sum of the previous pair in a separate variable. Finally, we find the **largest difference** between two pairs. If it is **0**, print **“Yes”** + the value, otherwise - **“No”** + the difference.
367+
We read the input numbers **in pairs**. For each pair, we calculate the **sum**. While reading the input pairs, for each pair, except the first one, we have to calculate **the difference with the previous one**. To do that, we need to store the sum of the previous pair in a separate variable. Finally, we find the **largest difference** between the two pairs. If it is **0**, print **“Yes”** + the value, otherwise - **“No”** + the difference.
368368

369369
#### Testing in The Judge System
370370

371371
Test your solution here: [https://judge.softuni.org/Contests/Practice/Index/655#11](https://judge.softuni.org/Contests/Practice/Index/655#11).
372372

373373

374-
## Problem: Graphical and web applications
374+
## Problem: Graphical and Web Applications
375375

376-
In the current chapter, we learned about **loops** as a construction in programming that allows us to repeat a given action or a group of actions many times. Now let us play with them. To do that, we will draw some figures that will consist of many repeating graphical elements. This time, we will not do it in the console but in a graphical environment using "**turtle graphics**". It will be interesting. And it is not at all complicated. Try it!
376+
In the current chapter, we learned about **loops** as construction in programming that allows us to repeat a given action or a group of actions many times. Now let us play with them. To do that, we will draw some figures that will consist of many repeating graphical elements. This time, we will not do it in the console but in a graphical environment using "**turtle graphics**". It will be interesting. And it is not at all complicated. Try it!
377377

378378
### Problem: Turtle Graphics GUI Application
379379

@@ -386,7 +386,7 @@ Let us get familiar with **the concept of drawing "Turtle Graphics"**. Take a lo
386386
* Article on "turtle graphics" in Wikipedia – [https://en.wikipedia.org/wiki/Turtle_graphics](https://en.wikipedia.org/wiki/Turtle_graphics)
387387
* Interactive online tool for drawing with a turtle – [https://blockly-games.appspot.com/turtle](https://blockly-games.appspot.com/turtle)
388388

389-
We will start by creating a new **Java project** in **IntelliJ IDEA**. Add new package **`app`** (earlier in this chapter we described how to do it). Download **`MyTurtle.java`** and **`jturtle-0.1.1.jar`** from [https://github.com/SoftUni/Programming-Basics-Book-Java-EN/tree/master/assets/chapter-5-1-assets](https://github.com/SoftUni/Programming-Basics-Book-Java-EN/tree/master/assets/chapter-5-1-assets). **`MyTurtle.java`** is a pre-written class, which will help us get acquainted faster with the library **`jturtle-0.1.1.jar`**, which runs **the turtle**. Using file explore, we copy **`MyTurtle.java`** into the directory **`app`** of the project. Then we need to add the external library **`jturtle-0.1.1.jar`** in our project. This is done as follows:
389+
We will start by creating a new **Java project** in **IntelliJ IDEA**. Add a new package **`app`** (earlier in this chapter we described how to do it). Download **`MyTurtle.java`** and **`jturtle-0.1.1.jar`** from [https://github.com/SoftUni/Programming-Basics-Book-Java-EN/tree/master/assets/chapter-5-1-assets](https://github.com/SoftUni/Programming-Basics-Book-Java-EN/tree/master/assets/chapter-5-1-assets). **`MyTurtle.java`** is a pre-written class, which will help us get acquainted faster with the library **`jturtle-0.1.1.jar`**, which runs **the turtle**. Using file explore, we copy **`MyTurtle.java`** into the directory **`app`** of the project. Then we need to add the external library **`jturtle-0.1.1.jar`** in our project. This is done as follows:
390390
* Select **Project Structure** from the **File** menu (CTRL + SHIFT + ALT + S).
391391
* Click on **Select Modules** in the left pane.
392392
* Click on the **Dependencies** tab.
@@ -406,7 +406,7 @@ In the next window, click [**OK**], and we are ready to open **`MyTurtle.java`**
406406

407407
![](assets/chapter-5-1-images/13.Turtle-graphics-06.png)
408408

409-
#### Main methods in `Turtle`class
409+
#### Main Methods in `Turtle` Class
410410

411411
These are the main actions in `Turtle` class with which we draw:
412412

@@ -543,4 +543,4 @@ Add [**Triangle**] button, which draws three triangles with 22 vertices each, as
543543

544544
Draw in a loop by moving forward and rotating. In each step, increase the length of the forward step by 10 and rotate 120 degrees. Repeat 3 times for the three triangles.
545545

546-
If you have a problem with the exercises above, ask for help in the official **SoftUni Reddit Forum**: https://www.reddit.com/r/softuni/.
546+
If you have a problem with the exercises above, ask for help in the official **SoftUni Reddit Forum**: https://www.reddit.com/r/softuni/.

0 commit comments

Comments
 (0)