Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package methods;
- import java.util.Scanner;
- public class P09GreaterOfTwoValues {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String type = scanner.nextLine();
- switch (type) {
- case "int":
- int firstNum = Integer.parseInt(scanner.nextLine());
- int secondNum = Integer.parseInt(scanner.nextLine());
- System.out.println(getMax(firstNum, secondNum));
- break;
- case "char":
- char firstChar = scanner.nextLine().charAt(0);
- char secondChar = scanner.nextLine().charAt(0);
- System.out.println(getMax(firstChar, secondChar));
- break;
- case "string":
- String firstText = scanner.nextLine();
- String secondText = scanner.nextLine();
- System.out.println(getMax(firstText, secondText));
- break;
- }
- }
- public static int getMax(int firstNum, int secondNum) {
- if (firstNum > secondNum) {
- return firstNum;
- }
- return secondNum;
- }
- public static char getMax(char firstChar, char secondChar) {
- if (firstChar > secondChar) {
- return firstChar;
- }
- return secondChar;
- }
- public static String getMax(String firstText, String secondText) {
- String maxText = "";
- if (firstText.compareTo(secondText) > 0) {
- maxText = firstText;
- } else {
- maxText = secondText;
- }
- return maxText;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement