728x90
import java.util.Scanner;
public class TwoArrays {
public static int findSmallest(int[][] myArray) {
int result = myArray[0][0];
for (int i = 0; i < myArray.length; i++) {
for (int j = 0; j < myArray[i].length; j++) {
if (result > myArray[i][j]) {
result = myArray[i][j];
}
}
}
return result;
}
public static int findBiggest(int[][] myArray) {
int result = myArray[0][0];
for (int i = 0; i < myArray.length; i++) {
for (int j = 0; j < myArray[i].length; j++) {
if (result < myArray[i][j]) {
result = myArray[i][j];
}
}
}
return result;
}
public static int[][] createArray(int k, Scanner user_input) {
int[][] four = new int[k][];
for (int i = 0; i < k; i++) {
four[i] = new int[i + 1];
for (int j = 0; j <= i; j++) {
four[i][j] = user_input.nextInt();
}
}
return four;
}
public static void main(String[] args) {
Scanner user_input = new Scanner(System.in);
System.out.println("Enter the number of rows for the triangle array:");
int k = user_input.nextInt();
int[][] myArray = createArray(k, user_input);
int smallest = findSmallest(myArray);
int biggest = findBiggest(myArray);
System.out.println("The smallest number in the array is: " + smallest);
user_input.close();
}
}
728x90
'호그와트' 카테고리의 다른 글
내가 밖에서 시로 봤는데 흠흐밍 흠흐밍 하면서 돌아다니더라 (0) | 2023.12.08 |
---|---|
panda's attack (0) | 2023.11.17 |
어이 김 씨, 한국은 춥댜 ~ (0) | 2023.11.14 |
실제의 해킹을 잘하고 싶다면... (0) | 2023.11.12 |
치킨버거 맛 좀 볼래요? (0) | 2023.11.09 |