-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMethodsArrays.java
67 lines (46 loc) · 1.38 KB
/
MethodsArrays.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.util.*;
import java.util.Arrays;
class MethodsArrays
{
public static void main(String[]args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter any size of array");
int size = in.nextInt();
int numbers[] = new int[size]; //declaration of array
System.out.println("Enter "+size +" numbers into array : ");
//Inputs
for(int i=0;i<size;i++)
{
numbers[i] = in.nextInt();
}
System.out.println();
//Search Number Method
System.out.println("Enter number which you want to find from array");
int n = in.nextInt();
int x = Arrays.binarySearch(numbers,n); // binarySearch method
if(x>=0)
{
System.out.println(n +" Is found at " +x +" index");
}else{
System.out.println(n +" Is not found at array . ");
}
System.out.println();
// Sort Method used for ascending order
System.out.println("Sorted Integers" );
Arrays.sort(numbers);
for(int i=0;i<numbers.length;i++)
{
System.out.println(numbers[i]);
}
System.out.println();
// Fill Method of Arrays
System.out.println("Enter number which you want to change from array ");
Arrays.fill(numbers,n); //fill() Method...
for(int i=0;i<size;i++)
{
//System.out.println(Arrays.toString(numbers));
System.out.println(numbers[i]);
}
}
}