Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class GreaterofTwoValues {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String command = scan.nextLine();
- switch (command) {
- case "int":
- int num = Integer.parseInt(scan.nextLine());
- int num2 = Integer.parseInt(scan.nextLine());
- int result = getMaxInteger(num, num2);
- System.out.println(result);
- break;
- case "char":
- char a = scan.nextLine().charAt(0);
- char b = scan.nextLine().charAt(0);
- getCharMax(a, b);
- break;
- case "String":
- String input = scan.nextLine();
- String input2 = scan.nextLine();
- String resultString = getStringMax(input, input2);
- System.out.println(resultString);
- break;
- }
- }
- static String getStringMax(String input, String input2) {
- if (input.compareTo(input2)>=0) {
- return input;
- }else {
- return input2;
- }
- }
- static void getCharMax (char a, char b) {
- if (a>b) {
- System.out.println(a);
- return;
- }
- System.out.println(b);
- }
- static int getMaxInteger(int num, int num2) {
- if (num > num2) {
- return num;
- }
- return num2;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment