Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Lab9GreaterOfTwoValues {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String type = scanner.nextLine();
- String firstInput = scanner.nextLine();
- String secondInput = scanner.nextLine();
- switch (type){
- case"int":
- System.out.println(getMax(Integer.parseInt(firstInput),Integer.parseInt(secondInput)));
- break;
- case"char":
- System.out.println(getMax(firstInput.charAt(0),secondInput.charAt(0)));
- break;
- case"string":
- System.out.println(getMax(firstInput,secondInput));
- break;
- }
- }
- private static int getMax(int firstInput, int secondInput) {
- return Math.max(firstInput,secondInput);
- }
- private static char getMax(char firstInput,char secondInput){
- if (firstInput > secondInput){
- return firstInput;
- }
- return secondInput;
- }
- private static String getMax( String firstInput,String secondInput){
- if (firstInput.compareTo(secondInput)>0){
- return firstInput;
- }
- return secondInput;
- }
- }
- /*You are given two values of the same type as input. The values can be of type int, char of String.
- Create a method getMax() that returns the greater of the two values: */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement