Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class ProblemNine {
- public static void main(String[] args) {
- /*
- Examples
- program user
- Please choose a type:
- 1 --> int
- 2 --> double
- 3 --> string 3
- Please enter a string: hello
- hello*
- program user
- Please choose a type:
- 1 --> int
- 2 --> double 2
- 3 --> string
- Please enter a double: 1.5
- 2.5
- */
- Scanner sc =new Scanner(System.in);
- System.out.println("Please choose a type: (1 --> int, 2 --> double, 3 --> string): ");
- int test = Integer.parseInt(sc.nextLine());
- switch(test) {
- case 1:
- System.out.println("Please enter an int:");
- int number = Integer.parseInt(sc.nextLine());
- number+=1;
- System.out.println(number);
- break;
- case 2:
- System.out.println("Please enter a double:");
- double numberTwo =Double.parseDouble(sc.nextLine());
- numberTwo+=1;
- System.out.println(numberTwo);
- break;
- case 3:
- System.out.println("Please enter a string:");
- String text =sc.nextLine();
- text =text + "*";
- System.out.println(text);
- break;
- default:
- System.out.println("Wrong input!");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement