Class Notes for While Loops |
|
public class Notes {
public static void main(String[] args) {
System.out.println( myName() );
myAddress();
System.out.println("4+7="+addThese(4,7));
System.out.println("The average of 95,87,60,100 is "+average(95,87,60,100));
double a= 7;
double b = 10;
double smallest = whichIsSmaller(a,b);
System.out.println("The smallest value is "+smallest);
}
// methods that returns a string
public static String myName(){
return "Adam Smith";
}
// method that doesn't return anything
public static void myAddress(){
System.out.println("9734 Bayou Woods");
System.out.println("Baytown Tx, 77521");
}
// method with two parameters
public static int addThese( int a, int b ){
int sum = a+b;
return sum;
}
// method with 4 parameters
public static double average(double a, double b, double c, double d){
double sum = a+b+c+d;
return sum/4.0;
}
//method with multiple returns
public static double whichIsSmaller(double a, double b){
if(a < b)
return a;
else
return b;
}
}
Create a class called MethodsAreHandy
- in the main class be sure to test all your methods you make.
1. Create a method (called myName) that returns your name as a string
2. Create a method (called addThese) that takes two doubles and returns a double. This method should add the two parameters.
3. Create a method (called subtractThese) that takes two doubles and returns a double. This method should subtract the two parameters.
4. Create a method (called whichIsBigger) that takes two doubles and returns a double. This method should compare the two parameters and return the largest.
- in the main class be sure to test all your methods you make.
1. Create a method (called myName) that returns your name as a string
2. Create a method (called addThese) that takes two doubles and returns a double. This method should add the two parameters.
3. Create a method (called subtractThese) that takes two doubles and returns a double. This method should subtract the two parameters.
4. Create a method (called whichIsBigger) that takes two doubles and returns a double. This method should compare the two parameters and return the largest.
Videos |
|