❮ Previous Next ❯

Largest.java

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);
}
}

Output

the largest item is:6

Sort.java

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]);
}
}
}

Output:

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

Search.java

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);
}
}

Output:

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.


❮ Previous Next ❯

Follow Us




  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved