class Largest { public static void main(String args[]) { int a[] = { 3, 5, 6, 2, 4 }; int i, large; large = a[0]; for (i = 1; i <= 4; i++) { if (a[i] > large) large = a[i]; } System.out.println("the largest item is:" + large); } }
the largest item is:6
import java.util.Scanner; class Sort { public static void main(String args[]) { int i, j, temp, size; Scanner s = new Scanner(System.in); System.out.println("Enter the size of the array"); size = s.nextInt(); int a[] = new int[size]; System.out.println("Enter the array elements"); for (i = 0; i < size; i++) { a[i] = s.nextInt(); } for (i = 0; i < size; i++) { for (j = 0; j < size - i - 1; j++) { if (a[j] > a[j + 1]) { temp = a[j]; a[j] = a[j + 1]; a[j + 1] = temp; } } } System.out.println("The array elements are in sorted order"); for (i = 0; i < size; i++) { System.out.println(a[i]); } } }
Enter the size of the array
5
Enter the array elements
3
6
1
9
7
The array elements are in sorted order
1
3
6
7
9
import java.util.Scanner; class Search { public static void main(String args[]) { int i,item,loc=-1,size; Scanner s= new Scanner(System.in); System.out.println("Enter the size of the array"); size=s.nextInt(); int a[]=new int[size]; System.out.println("Enter the array elements"); for(i=0;i<size;i++) { a[i]=s.nextInt(); } System.out.println("Enter the item to be searched"); item=s.nextInt(); for(i=0;i<size;i++) { if(item==a[i]) { loc=i; break; } } System.out.println("index location is"+loc); } }
Enter the size of the array
5
Enter the array elements
2
5
3
7
9
Enter the item to be searched
5
Index location is 1.
Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.
We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc