Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- public class Pr9GreateOfTwoValues {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- String type = reader.readLine();
- String str1 = reader.readLine();
- String str2 = reader.readLine();
- reader.close();
- getMax(type, str1, str2);
- }
- private static void getMax(String type, String str1, String str2) {
- if ("int".equals(type)) {
- int num1 = Integer.parseInt(str1);
- int num2 = Integer.parseInt(str2);
- if (num1 > num2) {
- System.out.println(num1);
- } else {
- System.out.println(num2);
- }
- } else if ("char".equals(type)) {
- char ch1 = str1.charAt(0);
- char ch2 = str2.charAt(0);
- if (ch1 > ch2) {
- System.out.println(ch1);
- } else {
- System.out.println(ch2);
- }
- } else if ("string".equals(type)) {
- int result = str1.compareTo(str2);
- if (result == 0)
- System.out.println("str1 and str2 are equal");
- else if (result < 0)
- System.out.println(str2);
- else
- System.out.println(str1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement