Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Main callMe = new Main();
- int[] numberArray = new int[5];
- int numSmallest = 0;
- // paano mo gagawin eto ng isang loop lang yung mga may .nextInt
- System.out.print("Enter number 1: ");
- numberArray[0] = sc.nextInt();
- System.out.print("Enter number 2: ");
- numberArray[1] = sc.nextInt();
- System.out.print("Enter number 3: ");
- numberArray[2] = sc.nextInt();
- System.out.print("Enter number 4: ");
- numberArray[3] = sc.nextInt();
- System.out.print("Enter number 5: ");
- numberArray[4] = sc.nextInt();
- numSmallest = numberArray[0];
- // paano mo gagamitan ng loop yung limang numCompare2
- numSmallest = callMe.numCompare2(numSmallest, numberArray[0]);
- numSmallest = callMe.numCompare2(numSmallest, numberArray[1]);
- numSmallest = callMe.numCompare2(numSmallest, numberArray[2]);
- numSmallest = callMe.numCompare2(numSmallest, numberArray[3]);
- numSmallest = callMe.numCompare2(numSmallest, numberArray[4]);
- System.out.println("numSmall: " + numSmallest);
- }
- public int numCompare2(int num1, int num2) {
- int small = 0;
- if (num1 < num2) {
- small = num1;
- } else {
- small = num2;
- }
- return small;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment