Advertisement
CR7CR7

dtt

Oct 12th, 2022
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. import java.util.Scanner;
  2. class Add{
  3.     Scanner scan =new Scanner(System.in);
  4.    
  5.     public static void main(String[] args){
  6.         Scanner scan =new Scanner(System.in);
  7.         String command =scan.nextLine();
  8.         String input =scan.nextLine();
  9.         switch (command){
  10.             case "int":
  11.                 int number = Integer.parseInt(input);
  12.                add(number);
  13.                 break;
  14.             case "real":
  15.                 double num = Double.parseDouble(input);
  16.                 add (num);
  17.                 break;
  18.             case "string":
  19.                 add (input);
  20.                 break;
  21.         }
  22.        
  23.              
  24.  
  25. }
  26.  
  27. private static void add(int number){
  28.      
  29.                
  30.                 number*=2;
  31.                 System.out.println(number);
  32.    
  33.    
  34. }  
  35. private static void add(double num){
  36.    
  37.     num*=1.50;
  38.     System.out.printf("%.2f",num);
  39.    
  40. }  
  41. private static void add(String input){
  42.        
  43.  
  44.         System.out.printf("$%s$",input);
  45. }
  46.  
  47. }  
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement