GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Create ProductOfArray.md · AlexaJavaDev/JavaArrays@ef80fc6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • ProductOfArray.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎ProductOfArray.md‎

Copy file name to clipboard
+32Lines changed: 32 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
**Что делает:**
2+
Перемножает все элементы массива (вычисляет произведение).
3+
4+
**Код:**
5+
```java
6+
public class ProductOfArray {
7+
public static void main(String[] args) {
8+
int[] str = {1, 2, 3, 4, 5};
9+
System.out.println(massiv(str));
10+
}
11+
12+
public static int massiv(int[] str) {
13+
int res = 1;
14+
15+
for (int i = 0; i < str.length; i++) {
16+
res *= str[i];
17+
}
18+
return res;
19+
}
20+
}
21+
```
22+
#### Пример вывода в консоли:
23+
```
24+
120
25+
```
26+
27+
---
28+
29+
#### Мои заметки:
30+
- Для суммы мы начинали с `0`, а для произведения — с `1` (умножение на 0 обнулит всё!)
31+
- `res *= str[i]` — то же самое, что `res = res * str[i]`
32+
- 1 × 2 × 3 × 4 × 5 = 120

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.