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
<!-- Kirjoita ohjelma, joka lukee käyttäjältä kokonaisluvun. Tämän jälkeen ohjelma tulostaa luvut nollasta käyttäjän syöttämään lukuun. Voit olettaa, että käyttäjä syöttää aina positiivisen luvun. Alla on muutamia esimerkkejä ohjelman toivotusta toiminnasta. -->
128
128
Write a program that reads an integer from the user. Then the program prints numbers from 0 to the number given by the user. You can assume that the user always gives a positive number. Below is some examples of the wanted functionality.
Copy file name to clipboardExpand all lines: data/osa-2/4-metodit.md
+17-23Lines changed: 17 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -320,13 +320,13 @@ Alussa olivat suo, kuokka ja Java.
320
320
321
321
How many times?
322
322
**7**
323
-
In a hole in the ground there lived a method.
324
-
In a hole in the ground there lived a method.
325
-
In a hole in the ground there lived a method.
326
-
In a hole in the ground there lived a method.
327
-
In a hole in the ground there lived a method.
328
-
In a hole in the ground there lived a method.
329
-
In a hole in the ground there lived a method.
323
+
In a hole in the ground there lived a method
324
+
In a hole in the ground there lived a method
325
+
In a hole in the ground there lived a method
326
+
In a hole in the ground there lived a method
327
+
In a hole in the ground there lived a method
328
+
In a hole in the ground there lived a method
329
+
In a hole in the ground there lived a method
330
330
331
331
</sample-output>
332
332
@@ -547,12 +547,12 @@ public static void main(String[] args) {
547
547
548
548
<!-- Luo tehtäväpohjaan metodi `public static void tulostaLuvustaYhteen(int luku)`, joka tulostaa luvut parametrina annetusta luvusta yhteen asti. Alla on kaksi esimerkkiä metodin käytöstä. -->
549
549
550
-
Create the following method in the exercise template: `public static void printFromParameterToOne(int number)`. It should print the numbers from the number passed as a parameter down to one. Two examples of the method's usage are given below.
550
+
Create the following method in the exercise template: `public static void printFromNumberToOne(int number)`. It should print the numbers from the number passed as a parameter down to one. Two examples of the method's usage are given below.
551
551
552
552
553
553
```java
554
554
publicstaticvoid main(String[] args) {
555
-
printFromParameterToOne(5);
555
+
printFromNumberToOne(5);
556
556
}
557
557
```
558
558
@@ -577,7 +577,7 @@ public static void main(String[] args) {
577
577
```java
578
578
579
579
publicstaticvoid main(String[] args) {
580
-
printFromParameterToOne(2);
580
+
printFromNumberToOne(2);
581
581
}
582
582
583
583
```
@@ -1552,7 +1552,7 @@ public static void main(String[] args) {
1552
1552
1553
1553
```java
1554
1554
publicstaticint greatest(int number1, int number2, int number3) {
1555
-
// write your code here
1555
+
// write some code here
1556
1556
}
1557
1557
1558
1558
publicstaticvoid main(String[] args) {
@@ -1620,8 +1620,8 @@ public static double average(int number1, int number2, int number3, int number4)
1620
1620
}
1621
1621
1622
1622
publicstaticvoid main(String[] args) {
1623
-
doubleanswer= average(4, 3, 6, 1);
1624
-
System.out.println("Average: "+answer);
1623
+
doubleresult= average(4, 3, 6, 1);
1624
+
System.out.println("Average: "+result);
1625
1625
}
1626
1626
```
1627
1627
@@ -2074,7 +2074,7 @@ Below is a visualization of the method call `multiplicationTable(3)`. Notice how
@@ -2107,7 +2107,7 @@ public static void main(String[] args) {
2107
2107
2108
2108
```java
2109
2109
publicstaticvoid printStars(int number) {
2110
-
//one start can be printed with the command
2110
+
//you can print one star with the command
2111
2111
// System.out.print("*");
2112
2112
// call the print command n times
2113
2113
// in the end print a line break with the comand
@@ -2141,15 +2141,13 @@ The output of the program:
2141
2141
2142
2142
<!-- Tee metodi `tulostaNelio(int sivunpituus)` joka tulostaa neliön käyttäen `tulostaTahtia`-metodia. Siis esimerkiksi kutsu `tulostaNelio(4)` tulostaa seuraavaa: -->
2143
2143
2144
-
Define a method called `printSquare(int lengthOfSide)` that prints a suitable square with the help of the `printStars` method. So the method call `printSquare(4)` results in the following output:
2144
+
Define a method called `printSquare(int size)` that prints a suitable square with the help of the `printStars` method. So the method call `printSquare(4)` results in the following output:
2145
2145
2146
2146
<sample-output>
2147
-
2148
2147
****
2149
2148
****
2150
2149
****
2151
2150
****
2152
-
2153
2151
</sample-output>
2154
2152
2155
2153
<!-- **Huom:** tehtävässä ei riitä että tulostus näyttää oikealta, tulostaNelio-metodin sisällä neliön "rivien" tulostus tulee tehdä tulostaTahtia-metodia käyttäen. -->
@@ -2167,14 +2165,12 @@ When creating the program, you might benefit from the test code in the main to e
2167
2165
2168
2166
<!-- Tee metodi `tulostaSuorakulmio(int leveys, int korkeus)` joka tulostaa suorakulmion käyttäen `tulostaTahtia`-metodia. Siis esimerkiksi kutsu `tulostaSuorakulmio(17,3)` tulostaa seuraavaa: -->
2169
2167
2170
-
Write a method called `printRectangle(int width, int height`) that prints the correct rectangle by using the `printStars` method. So the method call `printRectangle(17, 3)` should produce the following output:
2168
+
Write a method called `printRectangle(int width, int height)` that prints the correct rectangle by using the `printStars` method. So the method call `printRectangle(17, 3)` should produce the following output:
2171
2169
2172
2170
<sample-output>
2173
-
2174
2171
*****************
2175
2172
*****************
2176
2173
*****************
2177
-
2178
2174
</sample-output>
2179
2175
2180
2176
@@ -2187,12 +2183,10 @@ Write a method called `printRectangle(int width, int height`) that prints the co
2187
2183
Create a method called `printTriangle(int size)` that prints a triangle by using the `printStars` method. So the call `printTriangle(4)` should print the following:
0 commit comments