class Bubblesort
{
public static void main(String[] args)
{
int a[]={4,1,8,3,5};
int temp=0;
System.out.println("given array: ");
for(int j=0;j<5;j++)
{
System.out.print(a[j]);
}
System.out.println("");
System.out.println("Bubble sort for ascending order");
for(int j=0;<(a.length-1);j++)
{
for(int i=0;<(a.length-1);i++)
{
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
}
System.out.println("the sorted array is:");
for(int k=0;k<5;k++)
{
System.out.print(a[k]);
}
}
}
aDDa For All ===> Free downloads | eBooks | Softwares | SMS | Fun | News | Codes | Techie | Music | Movies
Mar 19, 2010
JAVA Program for Bubblesort (Ascending order) of a Single Dimensional Array
JAVA Program to Print the season of a given month
public class SeasonDownload this program Here
{
public static void main(String[] args)
{
int month=4;
switch(month)
{
case 1:
case 2:
case 3:
System.out.println("Automn");
break;
case 4:
case 5:
case 6:
System.out.println("summer");
break;
case 7:
case 8:
case 9:
System.out.println("winter");
break;
case 10:
case 11:
case 12:
System.out.println("spring");
break;
default:
System.out.println("Wrong input");
}
}
}
JAVA Program to to find whether the given number is Armstrong or not
class ArmstrongDownload this program Here
{
public static void main(String[] args)
{
int n=143,temp,a=0,i=1;
temp=n;
while(i>0)
{
i=n%10;
a=(i*i*i)+a;
n=n/10;
}
if(a==temp)
System.out.println("the given number is armstrong");
else
System.out.println("the given number is not armstrong");
}
}
JAVA Program to Print he Default Values
class DefaultvaluesDownload this program Here
{
static int a;
static byte b;
static char c;
static short s;
static long l;
static float f;
static double d;
static boolean bl;
public static void main(String[] args)
{
System.out.println("Default values of various data types");
System.out.println("int: "+a);
System.out.println("byte: "+b);
System.out.println("char: "+c);
System.out.println("short: "+s);
System.out.println("long: "+l);
System.out.println("float: "+f);
System.out.println("double: "+d);
System.out.println("boolean: "+bl);
}
}
Subscribe to:
Posts (Atom)