MethodDemo.java.html

  1  /**
  2     This example demonstrates method calls.
  3  */
  4  
  5  public class MethodDemo
  6  {
  7     public static void main(String[] args)
  8     {
  9        String greeting = "Hello, World!";
 10        System.out.println(greeting); 
 11           // greeting is the argument in this call to the println method
 12        int numberOfCharacters = greeting.length();
 13          // The length method returns a value
 14     
 15        System.out.print("numberOfCharacters: ");
 16        System.out.println(numberOfCharacters);
 17  
 18        // You can use the return value of one method as an argument of another method
 19  
 20        System.out.print("greeting.length(): ");
 21        System.out.println(greeting.length());
 22  
 23        // The replace method has two arguments
 24        String river = "Mississippi";
 25        river = river.replace("issipp", "our");
 26        System.out.print("river: ");
 27        System.out.println(river);
 28     }
 29  }