Anda di halaman 1dari 3

Array.

java

1 importjava.util.Scanner;
2 publicclassArray{
3
4 publicvoidcari(int[]a,intb)
5 {
6 intk=0;
7 intm=0;
8 for(inti=1;i<a.length;i++)
9 {
10 if(a[i]==b)
11 {
12 k=k+1;
13 m=i;
14 }
15 }
16 if(k>=1)
17 {
18 System.out.println("Posisiarrayke"+m);
19 }
20 else
21 {
22 System.out.println("1");
23 }
24 }
25
26 publicintrange(int[]a)
27 {
28 intb=a[0];
29 for(inti=1;i<a.length;i++)
30 {
31 if(a[i]>b)
32 {
33 b=a[i];
34 }
35 }
36
37 intk=a[0];
38 for(inti=1;i<a.length;i++)
39 {
40 if(a[i]<k)
41 {
42 k=a[i];
43 }
44 }
45
46 intr=bk+1;
47 returnr;
48 }
49
50 publicintcountInRange(inta[],intb,intc)
51 {inth=0;
52 for(inti=0;i<a.length;i++)
53 {
54 if((a[i]>=b)&&(a[i]<=c))
55 {
56 h=h+1;
57 }

Page1
Array.java

58 }
59 returnh;
60 }
61
62 publicbooleaninSorted(inta[])
63 {
64 intq=0;booleanr=true;
65 for(inti=0;i<a.length1;i++)
66 {
67 if(a[i]<a[i+1])
68 {
69 q=q+1;
70 }
71 }
72 if(q==(a.length1))
73 {
74 r=true;
75 }
76 else
77 {
78 r=false;
79 }
80 returnr;
81 }
82
83 publicstaticvoidmain(String[]args){
84 Scannerinput=newScanner(System.in);
85 System.out.println("Soalnomor1array");
86 System.out.print("Masukkanbanyakelemenarray:");
87 inta=input.nextInt();
88 int[]b=newint[a];
89 for(inti=0;i<b.length;i++)
90 {
91 System.out.print("Arrayke"+i+"=");
92 b[i]=input.nextInt();
93 }
94 System.out.print("Nilaiyangdicari:");
95 intc=input.nextInt();
96 Arrayy=newArray();
97 y.cari(b,c);
98
99 System.out.println("Soalnomor2array");
100 Arrayz=newArray();
101 z.range(b);
102 System.out.println("Range="+z.range(b));
103
104 System.out.println("Soalnomor3array");
105 System.out.print("Batasbawah:");
106 intd=input.nextInt();
107 System.out.print("Batasatas:");
108 inte=input.nextInt();
109
110 Arrayw=newArray();
111 w.countInRange(b,d,e);
112 System.out.println("Adasebanyak"+w.countInRange(b,d,e)+"bilanganantarabatas
atasdanbatasbawah");
113

Page2
Array.java

114 System.out.println("Soalnomor4array");
115 Arrayu=newArray();
116 System.out.print(u.inSorted(b));
117
118 }
119
120 }

Page3