Zadanie 1:
The code gives an error!
public static final String a = 123.toString();
Moje rozwiązanie:
public class ToString {public static final String a = (String) "123";
}
Zadanie 2:
Write function bmi that calculates body mass index (bmi = weight / height ^ 2).
if bmi <= 18.5 return "Underweight"
if bmi <= 25.0 return "Normal"
if bmi <= 30.0 return "Overweight"
if bmi > 30 return "Obese"
Moje rozwiązanie:
public class Calculate {
public static String bmi(double weight, double height) {
double a = weight;
double b = height;
double bmi = (double) (a / b);
if (bmi <= 18.5) {
return "Underweight";
}
if ((bmi <= 25.0)) {
return "Normal";
}
if (bmi <= 30.0) {
return "Overweight";
}
if (bmi > 30) {
return "Obese";
}
return null;
}}
Zadanie 3:
Make a simple function called greet that returns the most-famous
"hello world!".
Moje rozwiązanie:
public class HelloWorld {
public static String greet(){
return "hello world!";
}
}
Zadanie 4:
Vasya Pupkin just started learning Java and C#.
At first, he decided to write simple program
that was supposed to sum up two small numbers
(numbers and their sum fit in a byte),
but it didn't work. Vasya was too sad to find out
what is wrong. Help him to correct the mistake.
Moje rozwiązanie:
public class FirstClass {
byte a ;
byte b;
public static byte sum (byte a, byte b) {
byte c = (byte) (a + b);
return c;
}
}