Advertisement
CR7CR7

task9

Sep 23rd, 2022
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.97 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Homework9 {
  4.     public static void main(String[] args) {
  5.         System.out.println("Please choose a type:\n1 --> int\n2 --> double\n3 --> string");
  6.         Scanner scanner = new Scanner(System.in);
  7.         String one = scanner.nextLine();
  8.  
  9.         if (one.equals("1")) {
  10.             System.out.println("Please enter an integer:");
  11.         } else if (one.equals("2")) {
  12.             System.out.println("Please enter a double:");
  13.         }else if (one.equals("3")) {
  14.             System.out.println("Please enter a string:");
  15.         }
  16.         String two = scanner.nextLine();
  17.  
  18.         if (one.equals("1")) {
  19.             int input = Integer.parseInt(two);
  20.             System.out.println(++input);
  21.         } else if (one.equals("2")) {
  22.             double input = Double.parseDouble(two);
  23.             System.out.println(++input);
  24.         }else if (one.equals("3")) {
  25.             System.out.printf("%s*", two);
  26.         }
  27.     }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement