Skip to content

Instantly share code, notes, and snippets.

@bijay-shrestha
Created May 28, 2021 09:38
Show Gist options
  • Save bijay-shrestha/49bdc26836eee1eedcc2fc02af0f9d9a to your computer and use it in GitHub Desktop.
Save bijay-shrestha/49bdc26836eee1eedcc2fc02af0f9d9a to your computer and use it in GitHub Desktop.
/**
* Write a program to find out whether a given integer is present in an array or not.
**/
package com.hawa.practice;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class PracticeSetTwo {
public static void main(String[] args) {
int find = 13;
boolean found = false;
int[] arrayOfNumbers = {1, 2, 3, 4, 5};
for (int num : arrayOfNumbers) {
if (num == find) {
found = true;
break;
}
}
log.info("The number {} is found in an array {}. Result: {}", find, arrayOfNumbers, found);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment