-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrays.txt
65 lines (50 loc) · 1.86 KB
/
arrays.txt
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
import java.util.Scanner;
public class Arrays {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter the array:");
int count=sc.nextInt();
int[] a=new int[count];
System.out.println("enter the array elements:");
for(int i=0;i<count;i++)
{
a[i]=sc.nextInt(); // inserting array
}
for(int j=count-1;j>=0;j--){ //reverse array
System.out.println("Reversed array is"+a[j]);
}
if(count==5){
System.out.println("item found");
}
else{
System.out.println("not found");
}
//duplicate the value in array
for(int k=0;k<count;k++){
for(int l=k+1;l<count;l++){
if(a[k]==a[l]){
System.out.println("duplicate value is"+a[l]);
}
}
}
System.out.println("middle element is:"); // to find middle element in array
int g=count/2;
System.out.println(a[g]);
for(int i=0;i<count;i++){
for(int j=i+1;j<count;j++){
if(a[i]>a[j]){
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.println("sort array in ascending:"); // sort ascending
for(int i=0;i<count;i++){
System.out.println(a[i]);
}
System.out.println("sort in descending:"); //sort descending
for(int i=count-1;i>=0;i--){
System.out.println(a[i]);
}
}