OneCompiler

Java lesson practice

125

import java.util.*;
class Main {
public static void main(String[] args) {

    //Prob 5.3
    
    Scanner in = new Scanner(System.in);
    
    //Declaration of empty array which is lagayan ng number
    int []input = new int [5];
    //Int na mag cocontain ng number na hahanapin mamaya
    int target;
  
   //Print statement na nag aask sa user mag input ng 5 numbers
    System.out.println("Enter 5 numbers: ");
    
    //for loop,  to allow the user na mag input ng 5 numbers
    //the value of i at first is at index zero to tell the program na sa index 0 magstastart
    //then every time mag i-input yung user, the index location will increment every ikot, until mapuno na yung array
    for (int i=0; i<5; i++) {
        input[i]= in.nextInt();
    }
    
    //Print statement na nag aask sa user mag input ng number na want nya hanapin sa ininput nya sa taas
    System.out.println("Enter number that you want to find: ");
    target = in.nextInt();
    
    //hanapan session kung nasa input numbers ba yung number na ini-input kanina sa gustong hanapin.
    
    boolean found = false;
    for (int i=0; i<5; i++) {
        if (target == input [i]){
            found = true;
            break;
            // exit sa for loop after hanapin yung target
        }
    }
    
    //conditional statement kapag nakita or hindi nakita yung target
    if (found){
         System.out.println("Element is found");
    }
    else{
        System.out.print("Not found");
    } 
    
}

}