MrDoyle

16) Method Parameters

Jan 19th, 2021
841
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Robot{
  2.     public void speak(String text){
  3.         System.out.println(text);
  4.     }
  5.  
  6.     public void jump(int height){
  7.         System.out.println("Jumping: " + height);
  8.     }
  9.  
  10.     public void move(String direction, double distance){
  11.         System.out.println("Moving " + distance + " meters in direction " + direction);
  12.     }
  13. }
  14.  
  15.  
  16. public class App {
  17.  
  18.     public static void main(String[] args) {
  19.         Robot sam = new Robot();
  20.  
  21.         sam.speak("Hi I'm Sam.");
  22.         sam.jump(7);
  23.  
  24.         sam.move("West", 12.2);
  25.  
  26.         String greeting = "Hello there.";
  27.  
  28.         sam.speak(greeting);
  29.  
  30.         int value = 14;
  31.         sam.jump(value);
  32.     }
  33. }
RAW Paste Data