Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package softuni;
- import java.text.DecimalFormat;
- import java.util.Scanner;
- public class SoftUni {
- static int getMax(int num1,int num2){
- if(num1 > num2){
- return num1;
- }
- else if(num1 < num2){
- return num2;
- }
- else{
- return num1;
- }
- }
- static char getMax(char one,char two){
- if(one > two){
- return one;
- }
- else if(two > one){
- return two;
- }
- else{
- return two;
- }
- }
- static String getMax(String first,String second){
- if(first.compareTo(second) >= 0){
- return first;
- }
- else{
- return second;
- }
- }
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter the value type: ");
- String type = sc.nextLine();
- if(type.equals("int")){
- System.out.print("Enter the first number: ");
- int first = Integer.parseInt(sc.nextLine());
- System.out.print("Enter the second number: ");
- int second = Integer.parseInt(sc.nextLine());
- int result = getMax(first,second);
- System.out.println("The bigger is: " + result);
- }
- else if(type.equals("char")){
- System.out.print("Enter the first character: ");
- char first = sc.next().charAt(0);
- System.out.print("Enter the secodn character: ");
- char second = sc.next().charAt(0);
- char result = getMax(first,second);
- System.out.println("The bigger is: " + result);
- }
- else if(type.equals("string")){
- System.out.print("Enter the first word: ");
- String first = sc.nextLine();
- System.out.print("Enter the second word: ");
- String second = sc.nextLine();
- String result = getMax(first,second);
- System.out.println("The bigger is: " + result);
- }
- else{
- System.out.println("Wrong type!");
- }
- }
- }
Add Comment
Please, Sign In to add comment