Showing posts with label Program Examples. Show all posts
Showing posts with label Program Examples. Show all posts

Thursday, 28 July 2011

Program to enter a 5*5 matrix and display it


class matrix
{
Public static void main (String arg [])
{
int two [] [] = new int [5] [5];
{
int i,j,k =0;
for (i= 0; i<5 ; i++) {
for (j=0 ; j<5; j++)
{
Two [i] [j] = k;
k++;
} }
for (i=0; k=5 ;i++)
{
for (j=0; j<5 ; j++)
{
System.out.print( two [i] [i] + “  “ );
}
System.out.println( );
}
}
}

A simple program to arrange the 10 nos. in ascending order using array.


class ASC
{
Public static void main (String arg[])
{
int I,j,k;
int a[] ={10,12,18,16,3};
for (i=1;i<5;i++)
{
for(j=0;j<=3;j++)
{
if(a[j] > = a [ j+ 1])
{
k=a [j];
a[j]=a[j+1]
a[j+1]=k;
}
}
}
for(i=0;i<5;i++)
{
System.out.println (a [i]);
}
}
}

A simple program to find the average of 10 nos. using array class Arg



class Arg
{
Public static void main (string arg [])
{
int no []= { 10 ,12 , 14 ,16 ,18 ,20 ,22, 24 ,26 28);
int result = 0;
for (i=0; i<10;i++)
result =result + no [i];
System.out.println(“Average is “ +result/10);
}
}

Wednesday, 27 July 2011

Simple program for printing the following chatuskon upto given value and print the patter for “*”



                        *
                                                                                                    *                  *                  *                                                                                                 
                                                                                *                  *                  *                  *                  *
                                                            *                  *                  *                  *                  *                  *                  *
                                        *                  *                  *                  *                  *                  *                  *                  *                  *




class a1

{

Public static void main (String args[])

{

int I,j,k,1;

for(i=1;i<=5;i++)

{

for(1=5;1>=I;1--)

System.out.print(“\t”)

for(j=1:j<=I;j++)

System.out.print(“*\t”);

for(k=i-1;k=1;k--)

System.out.print(“*\t”);

System.out.println();
}
}









simple program for printing the following pyramid using for loop



                                                            1                  2                 1
                                       1                  2                 3                 2                 1
       1                  2                 3                 4                 3                 2                 1
1                 2                 3                 4                 5                 4                 3                 2                 1




class a

{

Public static void main(String args[])

{

int I,j,k,l;
for(i=1; i<=5;i++)

{

for(i=5;1>=I;1--)

System.out.printl(“\t”)

for(j=1;j<=I;j++)

System.out.println(J+”\t”);

for(k=i-1;k=1;k--)

System.out.print(k+”\t”);

System.out.println( );

}

}

Program for Printing the following pyramid



1
2 2
3 3 3
4 4 4 4
n n n ………………n

class series
{

Public static void main (String args[])
{

int i,j,n;
n=50;

for(i=1;i<=50; i++ )

{

for(j=1;j<=1;j++)

{

system.out.print (i);

}

system.out.println (“ “);

}
}
}

Simple program for making Pyramid using only while loop


1
1 2
1 2 3
1 2 3 4
1 2 3 4…..N

class series
{

Public static void main (String args [])

{

int N=10; i=1; j=1;
while( i<N)

{

j=1;
while(J<=i)

{

System.out.println(j);
J++;

}

System.out.println(“”);
i++;

}
}
}








Program to find the greater number from the three nos. using nested if else statement


Classs max
{
             Public static void main (String args[]) 

             {

Int a,b,c;
A=25; b=30; c=10;
if(a>b)

             {

if(a<c)

System.out.println(“a is maximum”);

else

System.out.println(“c is maximum”);

}
else

if(b>c)

System.out.printl(“b is maximum”);

else

System.out.printl(“c is maximum”);
}
               }

}

A simple program for addition of two values:



Class addition
{
Public static void main (String args[])
   {
int a = 5, b=10;
int c= a+ b;

System.out.println(“the sum of two value is :” +c);

    }
}

Twitter Delicious Facebook Digg Stumbleupon Favorites More