Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Greater_Of_Two_Values {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- if (input.equals("int")){
- int first = Integer.parseInt(scanner.nextLine());
- int second = Integer.parseInt(scanner.nextLine());
- System.out.println(bigger(first, second));
- } else if (input.equals("char")){
- char first = scanner.nextLine().charAt(0);
- char second = scanner.nextLine().charAt(0);
- System.out.println(bigger(first, second));
- } else if (input.equals("String")){
- String first = scanner.nextLine();
- String second = scanner.nextLine();
- System.out.println(bigger(first, second));
- }
- }
- public static String bigger (String first, String second){
- if (first.compareTo(second) >= 0){
- return first;
- } else {
- return second;
- }
- }
- public static int bigger (int first, int second){
- if (first > second){
- return first;
- } else {
- return second;
- }
- }
- public static char bigger (char first, char second){
- if (first > second){
- return first;
- } else {
- return second;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement