Erinevus lehekülje "ITI0011:praktikum 02" redaktsioonide vahel
Mine navigeerimisribale
Mine otsikasti
| 12. rida: | 12. rida: | ||
<source lang="java"> | <source lang="java"> | ||
| + | /** | ||
| + | * EX00 solution | ||
| + | * Created by who? on 3.02.2016. | ||
| + | */ | ||
| + | public class EX00 { | ||
| + | /** | ||
| + | * Add two numbers. | ||
| + | * | ||
| + | * @param a first number | ||
| + | * @param b second number | ||
| + | * @return sum | ||
| + | */ | ||
| + | public static int sum(int a, int b) { | ||
| + | return a + a; | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Check whether the number is even. | ||
| + | * | ||
| + | * @param number the number to check | ||
| + | * @return true if even, false if odd | ||
| + | */ | ||
| + | public static boolean isEven(int number) { | ||
| + | if (number == 1) { | ||
| + | return false; | ||
| + | } | ||
| + | if (number == 2) { | ||
| + | return true; | ||
| + | } | ||
| + | if (number == 3) { | ||
| + | return false; | ||
| + | } else { | ||
| + | return true; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | /** | ||
| + | * Program entry point | ||
| + | * @param args system arguments | ||
| + | */ | ||
| + | public static void main(String[] args) { | ||
| + | System.out.println(sum(2, 2)); | ||
| + | System.out.println(isEven(2)); | ||
| + | |||
| + | } | ||
| + | } | ||
| + | |||
</source> | </source> | ||
Redaktsioon: 3. veebruar 2016, kell 14:05
2. praktikumi (3. - 5. veebruar) info
Teemad
- Muutujad: Java:Muutujad, JavaPython:Muutujad
- Funktsioonid: Java:Funktsioonid, JavaPython:Funktsioonid
- Koodi testimine
- git
Testimiseks kasutatav kood
<source lang="java"> /**
* EX00 solution * Created by who? on 3.02.2016. */
public class EX00 {
/**
* Add two numbers.
*
* @param a first number
* @param b second number
* @return sum
*/
public static int sum(int a, int b) {
return a + a;
}
/**
* Check whether the number is even.
*
* @param number the number to check
* @return true if even, false if odd
*/
public static boolean isEven(int number) {
if (number == 1) {
return false;
}
if (number == 2) {
return true;
}
if (number == 3) {
return false;
} else {
return true;
}
}
/**
* Program entry point
* @param args system arguments
*/
public static void main(String[] args) {
System.out.println(sum(2, 2));
System.out.println(isEven(2));
}
}
</source>