"HR30 Day 14: Scope/Java"의 두 판 사이의 차이

(새 문서: 분류: 30 Days of Code ==개요== * HR30 Day 14: Scope <source lang='java'> import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.re...)
 
1번째 줄: 1번째 줄:
[[분류: 30 Days of Code]]
[[분류: HR30 Java]]
==개요==
==개요==
* [[HR30 Day 14: Scope]]
* [[HR30 Day 14: Scope]]

2021년 10월 12일 (화) 23:54 판

개요

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

class Difference {
  	private int[] elements;
  	public int maximumDifference;
    Difference(int[] a) {
        this.elements = a;
    }
    public void computeDifference() {
        int max = 1;
        int min = 100;
        for(int num:this.elements) {
            if( num > max ) max = num;
            if( num < min ) min = num;
        }
        this.maximumDifference = max - min;
    }
} // End of Difference class

public class Solution {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();

        Difference difference = new Difference(a);

        difference.computeDifference();

        System.out.print(difference.maximumDifference);
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}