SasukeSlayer

Untitled

Oct 15th, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.36 KB | None | 0 0
  1. public class EckMethods
  2. {
  3.   public static void main(String[] args)
  4.   {
  5.    
  6.     int x = 7, y = 45;
  7.     String s = "yes";
  8.     String s2 = "abcdefg";
  9.     String s3 = "It will be cold out today.";
  10.    
  11.     printSum(x, y);
  12.     printDifference(x, y);
  13.     printProduct(x, y);
  14.     printQuotient(x, y);
  15.     printMod(x, y);
  16.    
  17.     printFirstCharacter(s);
  18.     printContains(s2);
  19.     printStringReplace(s3);
  20.   }
  21.     // A call to a method that prints the sum of x and y
  22.     public static void printSum(int num1, int num2){
  23.       int sum;
  24.       sum = num1 + num2;
  25.      
  26.       System.out.println(sum);
  27.     }
  28.    
  29.     // A call to a method that prints the difference of x and y
  30.     public static void printDifference(int num1, int num2){
  31.       int dif;
  32.       dif = num1 - num2;
  33.      
  34.       System.out.println(dif);
  35.     }
  36.    
  37.     // A call to a method that prints the product of x and y
  38.     public static void printProduct(int num1, int num2){
  39.       int prod;
  40.       prod = num1 * num2;
  41.    
  42.       System.out.println(prod);
  43.     }
  44.    
  45.     // A call to a method that prints the quotient of x and y
  46.     // Make sure to test whether the divisor is 0 - we don't want run time errors!
  47.     public static void printQuotient(int num1, int num2){
  48.        int quo;
  49.        quo = num1 / num2;
  50.        
  51.        if (num2 == 0){
  52.          System.out.println(" Divisor is 0. Exiting. ");
  53.          System.exit(0);
  54.        }else
  55.          System.out.println(quo);    
  56.     }
  57.    
  58.     // A call to a method that prints result of x modulus y
  59.     public static void printMod(int num1, int num2){
  60.        int mod;
  61.        mod = num1 % num2;
  62.        
  63.        System.out.println(mod);
  64.     }
  65.    
  66.     // A call to a method that prints the first character of a string
  67.     public static void printFirstCharacter(String str){
  68.      
  69.       System.out.println(str.charAt(0));      
  70.     }
  71.    
  72.     // A call to a method that prints whether the string contains the letter n
  73.     // You can use the string method indexOf or contains
  74.     public static void printContains(String str){
  75.      
  76.       System.out.println(str.contains("n"));    
  77.     }
  78.    
  79.     // A call to a method that replaces one string with another
  80.     // You can use the string method replace
  81.     public static void printStringReplace(String str){
  82.    
  83.       System.out.println(str.replace("cold", "warm"));
  84.     }
  85.   }
Advertisement
Add Comment
Please, Sign In to add comment