Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class GreaterOfTwoValues {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String typeVariable = sc.nextLine();
- if (typeVariable.equals("int")) {
- int n1 = Integer.parseInt(sc.nextLine());
- int n2 = Integer.parseInt(sc.nextLine());
- System.out.println(getMax(n1, n2));
- } else if (typeVariable.equals("char")) {
- char ch1 = sc.nextLine().charAt(0);
- char ch2 = sc.nextLine().charAt(0);
- System.out.println(getMax(ch1, ch2));
- } else if (typeVariable.equals("string")) {
- String str1 = sc.nextLine();
- String str2 = sc.nextLine();
- System.out.println(getMax(str1, str2));
- }
- }
- private static int getMax(int n1, int n2) {
- int res = 0;
- res = Math.max(n1, n2);
- return res;
- }
- private static char getMax(char ch1, char ch2) {
- char res = ' ';
- if (ch1 > ch2) {
- res = ch1;
- } else {
- res = ch2;
- }
- return res;
- }
- private static String getMax(String str1, String str2) {
- String res = "";
- if (str1.length() > str2.length()) {
- res = str1;
- } else {
- res = str2;
- }
- return res;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement