1. 程式人生 > >1140-面向物件程式設計上機練習一(函式過載)-JAVA

1140-面向物件程式設計上機練習一(函式過載)-JAVA

面向物件程式設計上機練習一(函式過載)

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

利用陣列和函式過載求5個數最大值(分別考慮整數、單精度、長整數的情況)。

Input

分別輸入5個int型整數、5個float 型實數、5個long型正整數。

Output

分別輸出5個int型整數的最大值、5個float 型實數的最大值、5個long型正整數的最大值。

Sample Input

11 22 666 44 55
11.11 22.22 33.33 888.88 55.55
1234567 222222 333333 444444 555555

Sample Output

666
888.88
1234567

Hint

Source

import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int maxint = 0;
		for (int i = 0; i < 5; i++) {
			int a = scanner.nextInt();
			if (maxint < a) {
				maxint = a;
			}
		}
		float maxfloat = 0;
		for (int i = 0; i < 5; i++) {
			float b = scanner.nextFloat();
			if (maxfloat < b) {
				maxfloat = b;
			}
		}
		long maxlong = 0;
		for (int i = 0; i < 5; i++) {
			long c = scanner.nextLong();
			if (maxlong < c) {
				maxlong = c;
			}
		}
		System.out.println(maxint);
		System.out.println(maxfloat);
		System.out.println(maxlong);
	}
}