The guide to everything controls for 1675 members.
double add(double a, double b) {
return a + b;
}
[return type] [name]([argument type] [argument name])
. A method can have any number of arguments separated by commas, including 0.void
(which means nothing) and in this case do not require a return
statement.System.out.println()
and Math.abs()
.public final class Main {
private Main() {
}
public static void printNameAndSchool(String fName, String lName, String school){
// Add your code here.
}
public static void main(String[] args) {
String firstName = "John";
String lastName = "Smith";
String school = "King";
System.out.println(firstName+" "+lastName+" goes to "+school);
firstName = "Jane";
lastName = "Smith";
school = "MSL";
System.out.println(firstName+" "+lastName+" goes to "+school);
}
}
printNameAndSchool(String first, String last, String school)
that returns nothing (void
)printNameAndSchool()
instead of printing each statement itself.
main()
method you should have only as many lines of code as you have members in your group.public static int mean(int a, int b)
public static double mean(double a, double b)
main()
method call each of your new functions and print the result:
System.out.println(mean(1,2));
and System.out.println(mean(1.0,2.0);
public static int min(int a, int b)
public static int max(int a, int b)
main()
method call each of your new functions and print the result:
System.out.println(min(1,5));
and System.out.println(max(1,5);
Methods.java
and copy the following code into the file: public final class Methods {
public static double checkIfNumberIsGreater(double x, double y) {
System.out.println("---------Cool Number Thing----------\n");
// Fill in your method here
// Think back to if/else statements. Call someone over if you need help.
// Create code to check if x is greater than y, and if true,
// add 2 to x (x = x + 2), then print out "x is greater than y"
// Then create code that adds 1 to y if it is greater than x,
// and then print out "x is NOT greater than y"
double z = 0;
// Then set z equal to the sum of x and y
System.out.println("The sum of x and y is: " + z + "\n");
return z;
}
public static void main(String... args) {
double a = 9.4;
double b = 8.7;
// Replace this line with a call to checkIfNumberIsGreater() and pass a and b as parameters.
// Then save the result in a double named c.
a += c;
b = b + (2.5 * c);
// Call the method checkIfNumberIsGreater() here and pass a and b as parameters again.
}
}