Array searching is very important term in programming. Arrays cover a strong side of coding and used everywhere in all types of programming. In this problem we will check the existence of a number in an array. First, user will enter 5 numbers and then enter a number to check that number exist in array or not.
Source Code
package com.ancodingpoints.www; import java.util.Scanner; public class Array_Searching { public static void main (String [] args ) { Scanner input = new Scanner (System.in); int num [] = new int [5]; int s =0; for (int i = 0; i<5; i++) { System.out.println(" Enter Your Number "); num[i] = input.nextInt(); } System.out.println(" Enter Your Number to search in Array "); s = input.nextInt(); for(int i=0; i<5;i++) { if (num[i] == s) { System.out.println(" Your Number Exist in Array!"); } } } }
0 comments:
Post a Comment