0% found this document useful (0 votes)
81 views3 pages

Java Array Operations Guide

This Java code defines an Array class with methods to: 1. Search an integer array for a value and return its index or -1 if not found. 2. Calculate the range of values in an integer array by finding the maximum and minimum. 3. Count the numbers within a given range in an integer array. 4. Check if an integer array is sorted in ascending order. The main method tests each method on sample input arrays.

Uploaded by

idaayu17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views3 pages

Java Array Operations Guide

This Java code defines an Array class with methods to: 1. Search an integer array for a value and return its index or -1 if not found. 2. Calculate the range of values in an integer array by finding the maximum and minimum. 3. Count the numbers within a given range in an integer array. 4. Check if an integer array is sorted in ascending order. The main method tests each method on sample input arrays.

Uploaded by

idaayu17
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Array.

java

1 [Link];
2 publicclassArray{
3
4 publicvoidcari(int[]a,intb)
5 {
6 intk=0;
7 intm=0;
8 for(inti=1;i<[Link];i++)
9 {
10 if(a[i]==b)
11 {
12 k=k+1;
13 m=i;
14 }
15 }
16 if(k>=1)
17 {
18 [Link]("Posisiarrayke"+m);
19 }
20 else
21 {
22 [Link]("1");
23 }
24 }
25
26 publicintrange(int[]a)
27 {
28 intb=a[0];
29 for(inti=1;i<[Link];i++)
30 {
31 if(a[i]>b)
32 {
33 b=a[i];
34 }
35 }
36
37 intk=a[0];
38 for(inti=1;i<[Link];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<[Link];i++)
53 {
54 if((a[i]>=b)&&(a[i]<=c))
55 {
56 h=h+1;
57 }

Page1
[Link]

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([Link]);
85 [Link]("Soalnomor1array");
86 [Link]("Masukkanbanyakelemenarray:");
87 inta=[Link]();
88 int[]b=newint[a];
89 for(inti=0;i<[Link];i++)
90 {
91 [Link]("Arrayke"+i+"=");
92 b[i]=[Link]();
93 }
94 [Link]("Nilaiyangdicari:");
95 intc=[Link]();
96 Arrayy=newArray();
97 [Link](b,c);
98
99 [Link]("Soalnomor2array");
100 Arrayz=newArray();
101 [Link](b);
102 [Link]("Range="+[Link](b));
103
104 [Link]("Soalnomor3array");
105 [Link]("Batasbawah:");
106 intd=[Link]();
107 [Link]("Batasatas:");
108 inte=[Link]();
109
110 Arrayw=newArray();
111 [Link](b,d,e);
112 [Link]("Adasebanyak"+[Link](b,d,e)+"bilanganantarabatas
atasdanbatasbawah");
113

Page2
[Link]

114 [Link]("Soalnomor4array");
115 Arrayu=newArray();
116 [Link]([Link](b));
117
118 }
119
120 }

Page3

You might also like