Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MethodsMoreExercise;
- import java.util.Scanner;
- public class O1DataTypes {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String type = scanner.nextLine();
- String input = scanner.nextLine();
- printResult(type, input);
- }
- static void printResult(String type, String input) {
- switch (type) {
- case "int":
- int number = Integer.parseInt(input);
- System.out.println(number * 2);
- break;
- case "real":
- double realNumber = Double.parseDouble(input);
- double result = realNumber * 1.5;
- System.out.printf("%.2f", result);
- break;
- default:
- System.out.printf("$%s$", input);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment