Mr. Truncale - Robert E. Lee High School
  • Home
  • Digital Media
    • HTML
  • Video Game Design
  • Comp. Programming I
  • Comp. Programming II
  • AP Computer Science
  • 3D Printing
  • Teacher Resources
  • Contact Me

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.
​
TURN IN

Videos


Robert E. Lee High School
1809 Market
Baytown, TX 77520
281-420-4535
digital media | computer programming I and II | BIM
ap computer science | architectural cad | video game design
national technical honor society | contact me