Untitled
unknown
plain_text
4 years ago
923 B
6
Indexable
import java.util.Scanner; public class WhatOrder { // TODO: Define a generic method called checkOrder() that // takes in four variables of generic type as arguments. // The return type of the method is integer // MY ATTEMPT public static <T extends Comparable<T>> T checkOrder(T item1, T item2, T item3, T item4) { T result = item1; item1 = 1; return result; // Check the order of the input: return -1 for ascending, // 0 for neither, 1 for descending } public static void main(String[] args) { Scanner scnr = new Scanner(System.in); // Check order of four strings System.out.println("Order: " + checkOrder(scnr.next(), scnr.next(), scnr.next(), scnr.next())); // Check order of four doubles System.out.println("Order: " + checkOrder(scnr.nextDouble(), scnr.nextDouble(), scnr.nextDouble(), scnr.nextDouble())); } }
Editor is loading...