Upload files to "OOP/Java/Lab/Week3"
This commit is contained in:
parent
d7432df050
commit
490ff117eb
3 changed files with 74 additions and 27 deletions
|
@ -1,26 +1,27 @@
|
|||
import java.util.Scanner;
|
||||
public class ArraySearch {
|
||||
public static void main(String args[]){
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int flag=0,index=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:array){
|
||||
if(i == b){
|
||||
System.out.print(" a["+index+"]");
|
||||
flag++;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
if(flag==0){
|
||||
System.out.print("None. The input value does not exist in the array.");
|
||||
}
|
||||
}
|
||||
}
|
||||
import java.util.Scanner;
|
||||
public class ArraySearch {
|
||||
public static void main(String args[]){
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int flag=0,index=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:array){
|
||||
if(i == b){
|
||||
System.out.print(" a["+index+"]");
|
||||
flag++;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
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