Upload files to "OOP/Java/Lab/Week3"
This commit is contained in:
parent
a48eede8ad
commit
ee1a31b5e1
5 changed files with 103 additions and 0 deletions
23
OOP/Java/Lab/Week3/ArraySearch.java
Normal file
23
OOP/Java/Lab/Week3/ArraySearch.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
import java.util.Scanner;
|
||||
public class ArraySearch {
|
||||
public static void main(String args[]){
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int flag=0;
|
||||
|
||||
int[] array = {1,2,3,1,5,6,1,8,9};
|
||||
|
||||
System.out.println("Enter the search value:");
|
||||
int b = sc.nextInt();
|
||||
|
||||
System.out.println("The value is found at the locations: ");
|
||||
for(int i=0;i<9;i++){
|
||||
if(array[i] == b){
|
||||
System.out.print(" a["+i+"]");
|
||||
flag++;
|
||||
}
|
||||
}
|
||||
if(flag==0){
|
||||
System.out.print("None. The input value does not exist in the array.");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue