Number in array

Number in array

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

View Answers

July 18, 2011 at 2:50 PM

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");
        }

    }
}

June 7, 2012 at 6:12 PM

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









Related Tutorials/Questions & Answers:
Number in array
Number in array  How to write a program to check the number that we are entered from keyboard is in the given array
JavaScript Array of number
JavaScript Array of number     ... in understanding Java Script array number of elements. We are using JavaScript as script language. We declare an array variable that is used to store array object
Advertisements
USE ARRAY TO FIND THE LARGEST NUMBER AND OCCURRENCE
USE ARRAY TO FIND THE LARGEST NUMBER AND OCCURRENCE  i have some exercise from my lecturer and I still can't understand about ARRAY. here it is: write a program that reads 10 numbers from the keyboard. find the largest number
The Array Palindrome Number in Java
The Array Palindrome Number in Java       This is a Java simple palindrome number program... program. The array palindrome number arrange the array number. This session
How can we know the count/number of elements of an array?
How can we know the count/number of elements of an array?  How can we know the count/number of elements of an array
Find Second Largest Number from an Array
Find Second Largest Number from an Array This section illustrates you how to find the second largest number from an array. For this purpose, we have allowed... among them. Pulls the largest number out from the array and again check
ask user how many numbers to be inputted and determine the sum and highest number using an array in java
ask user how many numbers to be inputted and determine the sum and highest number using an array in java  ask user how many numbers to be inputted and determine the sum and highest number using an array in java
array
array  How to store the results of mysql query in an array... qurey in array: "select distinct(EMPLID)from tblwork where EMPLID not in (select (EMPLID) from tblmaster)" and i dont know the number of records. How can I
array
accepts a pointer to integer which represents an array of integer.After that this method prints the entire of the array numbers to the monitor. include using std::cout; using std::endl; void printArray(int *array, int count
PHP Array Count Values
PHP Array Count Values  Sometimes  we need to count the number of values, i.e. total number of appearance of an element, in an array. PHP provides array_count_values() function to count the number of variables.  General
c++ array find the average mark, highest mark, lowest mark, number of students passing,
c++ array find the average mark, highest mark, lowest mark, number of students passing,    i need help in adding the c++ code for the average mark, highest mark, lowest mark, number of students passing, using array. 01
c++ array find the average mark, highest mark, lowest mark, number of students passing,
c++ array find the average mark, highest mark, lowest mark, number of students passing,    i need help in adding the c++ code for the average mark, highest mark, lowest mark, number of students passing, using array. 01
Java count occurrence of number from array
Java count occurrence of number from array Here we have created an example that will count the occurrence of numbers and find the number which has the highest occurrence. Now for this, we have created an array of 15 integers
array
is an example that store some integers into an array and find the occurrence of each number from the array. import java.util.*; public class SearchNumberOccurrence...array  Hi i have array like {1,2,3,4,,5,5,6,6} then how can i
in_array
in_array  in_array in php
is _array()
is _array()  is _array()   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
is _array()
is _array()  is_array() in php   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
Array
indicating the person?s seat number and whether it is a Twin Seat or Normal Seat. It should also display the total number of Twin Seats and Normal Seats reserved. Use a one-dimensional array of primitive type Boolean to represent
Array
Array  how can i use elements of an array in a circular form? that is if the searching of the element reach the last elements of the array, then it will start serching from the begining of the array
Array in Java
An Array is the static memory allocation that holds a fixed number of values of same type in memory. The size or length of an array is fixed when the array is created. Each item in an array is called an element. First element
PHP array count
The PHP array_count_values() function is used to count the elements in the array. It returns the number of counting with values in associative array form. In returned array, key is the array's values and values are the number
Array
Array  is it possible to define array like this..? int[] intArray = new int[] {4,5,6,7,8}; Explain...?   Yes, you can. Java Initialize Array
Array
Array  What if i will not declare the limit index of an array, how will I declare an array and store values with it using loop?   Hi Friend... Scanner(System.in); int array[]=new int[5]; System.out.println("Enter
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
Array
Array  How do i insert elements into an array up to a limit from...("Enter Range: "); int size=input.nextInt(); int array[]=new int[size]; System.out.println("Enter Array Elements: "); for(int i=0;i<
array
array  WAP in java to store 6 element in array P and 4 element in array Q. Produce the third arra y R containing all element from p & q
Array
Array  can we create an array of size 1 lakh in java programming
array
array  array memory allocation is dynamic or static in java   Java Arrays have dynamic memory allocation
array
array  create an array in which no element is duplicate. if duplicate then tell to user duplicate. duplicacy is tell to user during when he enter the element
array
array  create an array in which no element is duplicate. if duplicate then tell to user duplicate. duplicacy is tell to user during when he enter the element
array
array  take a 2d array and display all its elements in a matrix fome using only one for loop and ple explain the program in below
array
array  wap to calculate reverse of 10 elements in an array?  ...(); } System.out.print("Array is: "); for(int i=0;i<arr.length;i...(); System.out.print("After reversing, Array is: "); for(int i=arr.length-1;i>=0
array
array  write a program in java which input n ,a natural number less than 12 and prints the natural number from 1 to n to the power 2 in the form of a spiral.the spiral should move in on anti clockwise direction starting from
Array's
Array's  I have to finish an "order page". that checks 2 dropdown boxes and a set of radio buttons and put the results into a set of textboxes, 1 line at a time, then calculate a total. I know I need to create an array, but I'm
array
array  how to getting values and storing values in array by using datainputstream?   Hi Friend, Try the following code:ADS_TO_REPLACE_1...("Array Elements are: "); for(int i=0;i<arr.length;i
JavaScript Add Element to Array
. This number starts from Zero (0) because whenever we assign any value to array it starts it's counting from 0 only. if an array is having the number 1(one... JavaScript Add Element to Array   
Two dimensional array in java
Two dimensional array in java. In this section you will learn about two-dimensional array in java with an example. As we know that array is a collection of similar data type or it can hold fixed number of value of same type. Two
Objective C Array
Objective C Array In a simple term we can say that array is a object, which is a collection of number of other objects. In Objective C, we can also add and remove the objects from the given list of array if the array is declared mutable
PHP Array Count
  Return Value Returns the number of elements in array...PHP Array Count Function To count the elements of an array PHP provides count() function. It counts all elements of an array or properties of an object
Array and input
Array and input  if this is my array int briefcases [ ]={1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26}; i want to ask user to input one of the above numbers then i want to print the array without the number
C Array Declaration
C Array Declaration       In this section, you will learn how to declare an array in C. To declare an array in C, you have to specify the name of the data type and the number
PHP Array Sizeof
PHP Array sizeof() function To count the elements of an array PHP provides sizeof() function. It counts all elements of an array or properties of an object... Format int sizeof( mixed $array [,int mode]) Parameters
Array Sizeof Function PHP
Array Sizeof Function PHP  Hi, How to count the number of elements in an array using the PHP Array sizeof() function? Please provides me online help links or example of array sizedof() PHP. Thanks
buzz number
buzz number  buzz number
using array
using array  display 10 digit number using array and print pyramid. 1 1 1 1 1 1 1 1 1 1 1 1
array - Java Beginners
array:5 what is the length of 2nd array:4 enter a number for 1st array: 4 enter a number for 1st array: 6 enter a number for 1st array: 2 enter a number for 1st array: 1 enter a number for 1st array: 7
PHP Push Array to Array
PHP Push Array to Array  array_push() function using array in PHP
prime number
prime number  get one number and check the number prime or not using if statement   Java Check Prime Number

Ads