-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.java
120 lines (105 loc) · 3.28 KB
/
array.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import java.util.Scanner;
import java.util.*;
public class array {
// public static void update(int marks[]) {
// for (int i = 0; i < marks.length; i++) {
// marks[i] = marks[i] + 1;
// }
// }
//Program for linear search using array
// public static int linearsearch(int numbers[],int key) {
// for(int i=0;i<numbers.length;i++){
// if(numbers[i] == key){
// return i;
// }
// }return -1;
// }
// public static String menucard(String menu[],String key) {
// //key ="dosa";
// for(int i=0;i<menu.length;i++){
// if(menu[i] == key)
// System.out.println("key is present in:"+i);
// }
// return null;
// }
//Program to get largest no.
public static int getlargestno(int numbers[]) {
int largest=Integer.MIN_VALUE;//-infinite
int smallest=Integer.MAX_VALUE;//+infinite
for(int i=0;i<numbers.length;i++){
if(largest<numbers[i]){
largest=numbers[i];
}
if(smallest>numbers[i]){
smallest=numbers[i];
}
}
System.out.println("smallest value:"+smallest);
return largest;
}
public static void main(String[] args) {
// datatype arrayname [] = new datatype[size];(here new keyword is use which
// search for empty space)
/*
* creating an array
* int marks[] = new int[50];
* int numbers[] = {1,2,3};
* String fruits[] = {"mango","orange","banana"};
*
*
* int phy[]={3,4,5,6,7};
* int chem[] = new int[50];
* int math[] = new int[50];
* for(int i=0;i<=4;i++){
* System.out.print(phy[i]+" ");
* }
*
* int marks[] = new int[50];
*
* System.out.println("array length is: " + marks.length);
*
* Scanner scan = new Scanner(System.in);
* marks[0]=scan.nextInt();
* marks[1]=scan.nextInt();
* marks[2]=scan.nextInt();
* System.out.println("phy:"+marks[0]);
* System.out.println("chem: "+marks[1]);
* System.out.println("maths: "+marks[2]);
* //updation
* // marks[2] = 100;
* // System.out.println("maths: "+marks[2]);
* int percentage =(marks[0]+marks[1]+marks[2])/3;
* System.out.println("average of marks: "+percentage+"%");
*
*
* passing arrays as argument
* 1.pass by value(variable is changed in fun but not reflected in main fun)
* 2.pass by reference(by calling fun array use reference)
* int marks[] = {99,98,97};
* update(marks);
* for(int i=0;i<marks.length;i++){
* System.out.print(marks[i]+" ");
* }
* System.out.println();
*/
int numbers[] = {2,4,5,7,56,54,38,36,20,32};
System.out.println("the largest no. is: "+(getlargestno(numbers)));
// int key=90;
// int index=linearsearch(numbers, key);
// if(index == -1){
// System.out.println("not found");
// }
// else{
// System.out.println("the key at index: "+index);
// }
// String key = "kebb";
// String menu[] = {"dosa","kebab","biryani","chole"};
// String index=menucard(menu,key);
// if(index==""){
// System.out.println("not found");
// }
// else{
// System.out.println("found");
// }
}
}