Advertisement
Guest User

Untitled

a guest
Jun 5th, 2021
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. package Methods;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class DataTypes {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String command = scanner.nextLine();
  9.         String input = scanner.nextLine();
  10.         switch (command){
  11.             case "int":
  12.                 int inp = Integer.parseInt(input);
  13.                 multiplyBy2 (inp);
  14.                 break;
  15.             case "real":
  16.                 double num = Double.parseDouble(input);
  17.                 realMultiplyAndFormat (num);
  18.                 break;
  19.             case "string":
  20.                 stringFormattedPrint (input); break;
  21.         }
  22.     }
  23.  
  24.     private static void multiplyBy2(int inp) {
  25.         inp *= 2;
  26.         System.out.println(inp);
  27.     }
  28.  
  29.     private static void realMultiplyAndFormat(double num) {
  30.         num *= 1.5;
  31.         System.out.printf("%.2f", num);
  32.     }
  33.  
  34.     private static void stringFormattedPrint(String input) {
  35.         System.out.printf("$%s$",input);
  36.     }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement