Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- * Created by zdravko on 19.02.19.
- */
- public class GreaterOfTwo {
- public static void main(String[] args) {
- Scanner console = new Scanner(System.in);
- String type = console.nextLine();
- if ("int".equals(type)){
- int first = Integer.parseInt(console.nextLine());
- int second = Integer.parseInt(console.nextLine());
- // first = Math.abs(first);
- // second = Math.abs(second);
- System.out.println(getGreater(first,second));
- } else if ("char".equals(type)){
- String str1 = console.nextLine();
- String str2 = console.nextLine();
- char ch1 = str1.charAt(0);
- char ch2 = str2.charAt(0);
- System.out.println(getGreater(ch1,ch2));
- } else if ("String".equals(type)){
- String word1 = console.nextLine();
- String word2 = console.nextLine();
- System.out.println(getGreater(word1,word2));
- }
- }
- static int getGreater(int n1,int n2){
- if (n1 >= n2){
- return n1;
- } else {
- return n2;
- }
- }
- static char getGreater(char ch1,char ch2){
- if (ch1 >= ch2){
- return ch1;
- } else {
- return ch2;
- }
- }
- static String getGreater(String word1,String word2){
- if (word1.compareTo(word2) >= 0){
- return word1;
- } else {
- return word2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement