public class methods {
public static void main(String[] args) {
//question 1:
HelloMessage();
//question 2:
double sum = sum(19.50, 100.60);
System.out.println(sum);
//question 3:
boolean number = number(9);
System.out.println(number);
//same
boolean number = isEven(12);
System.out.println(number);
//question 4:
String full_name = name("Mohamed " , " Abdirizak");
System.out.println(full_name);
//same
public static void main(String[] args) {
String marged = concatt("Najma" , " Daud" , " Abdi");
System.out.println(marged);
//question 5:
double num = remainder(30 , 12);
System.out.println(num);
double numb = remainder(40, 12);
System.out.println(numb);
//same Question 5:
public static void main(String[] args) {
remainder(28.5, 4.8);
}
1.
//we use method.
public static void HelloMessage() {
System.out.println("Hello world");
}
2.
public static double sum(double a, double b) {
double sum = a + b;
return sum;
}
3.
public static boolean number(int number) {
if(number %2 ==0) {
return true;
}
else {
return false;
}
}
//same
public static boolean isEven(int x) {
if(x%2 == 0)
return true;
else
return false;
}
4.
//we use Return Method.
public static String name(String firstName, String secondName) {
String full_name = firstName + secondName;
return full_name.toUpperCase();
}
//same
public static String concatt(String One , String Two, String Three) {
String marged = One + Two + Three;
return marged.toUppercase();
}
5.
public static double remainder(double x, double y) {
double remainder = x / y;
return remainder;
}
//same
public static void remainder(double x, double y) {
double remainder = x / y;
System.out.printf("remainder = %.2f ", remainder);
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter