Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class MethodTest {
- static void printResultByType(String a, int b) {
- int number = 0;
- if (a.equals("int")) {
- number = b;
- }
- int result = number * 2;
- System.out.println(result);
- }
- static void printResultByType(String a, double b) {
- double number = 0;
- if (a.equals("real")) {
- number = b;
- }
- double result = number * 1.5;
- System.out.printf("%.2f", result);
- }
- static void printResultByType(String a, String b) {
- if (a.equals("string")) {
- System.out.println("$" + b + "$");
- }
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String type = scanner.nextLine();
- if (type.equals("int")) {
- int command = Integer.parseInt(scanner.nextLine());
- printResultByType(type, command);
- } else if (type.equals("real")) {
- double command = Double.parseDouble(scanner.nextLine());
- printResultByType(type, command);
- } else {
- String command = scanner.nextLine();
- printResultByType(type, command);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement