Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EckMethods
- {
- public static void main(String[] args)
- {
- int x = 7, y = 45;
- String s = "yes";
- String s2 = "abcdefg";
- String s3 = "It will be cold out today.";
- printSum(x, y);
- printDifference(x, y);
- printProduct(x, y);
- printQuotient(x, y);
- printMod(x, y);
- printFirstCharacter(s);
- printContains(s2);
- printStringReplace(s3);
- }
- // A call to a method that prints the sum of x and y
- public static void printSum(int num1, int num2){
- int sum;
- sum = num1 + num2;
- System.out.println(sum);
- }
- // A call to a method that prints the difference of x and y
- public static void printDifference(int num1, int num2){
- int dif;
- dif = num1 - num2;
- System.out.println(dif);
- }
- // A call to a method that prints the product of x and y
- public static void printProduct(int num1, int num2){
- int prod;
- prod = num1 * num2;
- System.out.println(prod);
- }
- // A call to a method that prints the quotient of x and y
- // Make sure to test whether the divisor is 0 - we don't want run time errors!
- public static void printQuotient(int num1, int num2){
- int quo;
- quo = num1 / num2;
- if (num2 == 0){
- System.out.println(" Divisor is 0. Exiting. ");
- System.exit(0);
- }else
- System.out.println(quo);
- }
- // A call to a method that prints result of x modulus y
- public static void printMod(int num1, int num2){
- int mod;
- mod = num1 % num2;
- System.out.println(mod);
- }
- // A call to a method that prints the first character of a string
- public static void printFirstCharacter(String str){
- System.out.println(str.charAt(0));
- }
- // A call to a method that prints whether the string contains the letter n
- // You can use the string method indexOf or contains
- public static void printContains(String str){
- System.out.println(str.contains("n"));
- }
- // A call to a method that replaces one string with another
- // You can use the string method replace
- public static void printStringReplace(String str){
- System.out.println(str.replace("cold", "warm"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment