
How to write a program to check the number that we are entered from keyboard is in the given array or not

import java.util.*;
class CheckArray
{
public static void main(String[] args)
{
int array[]={1,2,3,4,5};
Scanner input=new Scanner(System.in);
System.out.print("Enter Number: ");
int num=input.nextInt();
boolean check=false;
for(int i=0;i<array.length;i++){
if(array[i]==num){
check=true;
}
}
if(check){
System.out.println("Given numbers is in the array");
}
else{
System.out.println("Given numbers is not in the array");
}
}
}

Many many thanks... I was badly stuck in this. But can you do me 1 more favour.. In the end How to find the total price of the books that has been purchased
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.