Guest User

Untitled

a guest
Jul 21st, 2020
59
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. public class MethodTest {
  4.  
  5.     static void printResultByType(String a, int b) {
  6.         int number = 0;
  7.         if (a.equals("int")) {
  8.             number = b;
  9.         }
  10.         int result = number * 2;
  11.         System.out.println(result);
  12.     }
  13.  
  14.     static void printResultByType(String a, double b) {
  15.         double number = 0;
  16.         if (a.equals("real")) {
  17.             number = b;
  18.         }
  19.         double result = number * 1.5;
  20.         System.out.printf("%.2f", result);
  21.     }
  22.  
  23.     static void printResultByType(String a, String b) {
  24.         if (a.equals("string")) {
  25.             System.out.println("$" + b + "$");
  26.         }
  27.     }
  28.  
  29.     public static void main(String[] args) {
  30.         Scanner scanner = new Scanner(System.in);
  31.         String type = scanner.nextLine();
  32.         if (type.equals("int")) {
  33.             int command = Integer.parseInt(scanner.nextLine());
  34.             printResultByType(type, command);
  35.         } else if (type.equals("real")) {
  36.             double command = Double.parseDouble(scanner.nextLine());
  37.             printResultByType(type, command);
  38.         } else {
  39.             String command = scanner.nextLine();
  40.             printResultByType(type, command);
  41.         }
  42.     }
  43. }
RAW Paste Data