Showing posts with label java free programs. Show all posts
Showing posts with label java free programs. Show all posts

Sunday, November 2, 2014

, , , ,

Program to print greater number in 2 numbers using if else in command line argument.



Code Box
-----------------------------------------

/* Program to print greater number in 2 numbers using 
if else in command line argument */


class greaterif
{
public static void main(String x[])
{
int a,b;

a=Integer.parseInt(x[0]);
b=Integer.parseInt(x[1]);

if(a>b)
{
System.out.print("\n a is greater a="+a);
}
else
{
System.out.print("\n b is greater b="+b);
}

}

}
Publisher: Brijmohan Lal Sahu - 3:32 AM
, , , ,

Program to print greater number in 2 numbers using conditional operator in command line argument.



Code Box
-----------------------------------------

/* Program to print greater number in 2 numbers using 
conditional operator in command line argument */


class greaterc
{
public static void main(String x[])
{
int a,b;

String s;

a=Integer.parseInt(x[0]);
b=Integer.parseInt(x[1]);


s=(a>b)?"a is greater a="+a:"b is grater b="+b;

System.out.print("\n"+s);

}

}
Publisher: Brijmohan Lal Sahu - 3:26 AM
, ,

Program to find area of circle using power function in command line argument.

area of circle

Code Box
--------------------------------------

/*Program to find area of circle using power function in command line argument */

class areacf
{
public static void main(String x[])
{

float a,r;

r=Float.parseFloat(x[0]);

System.out.print("\nRadius of circle is = "+r);

a=3.14f*(float)(Math.pow(r,2));

/* you can also write it as

a=3.14f*(Math.pow(r,2));
But in this case Math.pow(r,2) returns a double value not a
float that cause an error.
*/

System.out.print("\nAread of circle is = "+a);

}
}

Publisher: Brijmohan Lal Sahu - 3:20 AM

Saturday, November 1, 2014

, , , ,

Number Pattern 4 by while loop


Code Box by while loop
-----------------------------
/*program to print star pattern square box by while loop

  11111
  22222
  33333
  44444
  55555

*/

class npat4w
{
public static void main(String a[])
{
int n,i,j;
i=1;
n=Integer.parseInt(a[0]);

while(i<=n)
{j=1;
        while(j<=n)
        {
        System.out.print(i);
        j++;
}

System.out.print("\n");
i++;
}

}
}

Publisher: Brijmohan Lal Sahu - 1:13 AM

Sunday, September 22, 2013

, , , , ,

Number Pattern 9 by For Lop



Code Box by for loop
--------------------------

/*program to print star pattern square box by for loop

        1
       12
      123
     1234
    12345

*/

class npat9
{
public static void main(String a[])
{
int n,i,j,k;

n=Integer.parseInt(a[0]);

for(i=1;i&lt;=n;i++)
{
        for(j=n;j&gt;i;j--)
        {
        System.out.print(" ");
        }

        for(k=1;k&lt;=i;k++)
        {

        System.out.print(k);
        }
System.out.print("\n");

}
}

}

Publisher: Brijmohan Lal Sahu - 5:25 PM
, , , , , ,

Number Pattern 8 by For Loop



Code Box by for loop
---------------------------------

/*program to print star pattern square box by for loop

  5
  54
  543
  5432
  54321

*/

class npat8
{
public static void main(String a[])
{
int n,i,j;

n=Integer.parseInt(a[0]);

for(i=n;i>=1;i--)
{
        for(j=n;j>=i;j--)
        {
        System.out.print(j);
        }

System.out.print("\n");

}
}
}



Publisher: Brijmohan Lal Sahu - 5:23 PM
, , , , ,

Number Pattern 7 by for loop



Code Box by for loop
-----------------------------

/*program to print star pattern square box by for loop

  1
  21
  321
  4321
  54321

*/

class npat7
{
public static void main(String a[])
{
int n,i,j;

n=Integer.parseInt(a[0]);

for(i=1;i<=n;i++)
{
        for(j=i;j>=1;j--)
        {
        System.out.print(j);
        }

System.out.print("\n");

}

}


}



Publisher: Brijmohan Lal Sahu - 5:21 PM
, , , , , ,

Number Pattern 6 by for loop



Code Box by for loop
---------------------------
/*program to print star pattern square box by for loop

  55555
  44444
  33333
  22222
  11111
  

*/

class npat6
{
public static void main(String a[])
{
int n,i,j;

n=Integer.parseInt(a[0]);

for(i=n;i>=1;i--)
{
        for(j=1;j<=n;j++)
        {
        System.out.print(i);
        
}

System.out.print("\n");

}
}
}


Publisher: Brijmohan Lal Sahu - 5:18 PM
, , , ,

Number Pattern 5 by for loop



Code Box by for loop
-----------------------

/*program to print star pattern square box by for loop

  54321
  54321
  54321
  54321
  54321
  

*/

class npat5
{
public static void main(String a[])
{
int n,i,j;

n=Integer.parseInt(a[0]);

for(i=1;i<=n;i++)
{
        for(j=n;j>=1;j--)
        {
        System.out.print(j);
        
}

System.out.print("\n");

}
}
}



Publisher: Brijmohan Lal Sahu - 5:16 PM
, , , , , ,

Number Pattern 4 by for loop



Code Box by for loop
-------------------------
/*program to print number pattern square box by for loop

  11111
  22222
  33333
  44444
  55555

*/

class npat4
{
public static void main(String a[])
{
int n,i,j;

n=Integer.parseInt(a[0]);

for(i=1;i<=n;i++)
{
        for(j=1;j<=n;j++)
        {
        System.out.print(i);
        }

System.out.print("\n");

}
}
}


Publisher: Brijmohan Lal Sahu - 5:13 PM
, , , , ,

Number Pattern 3 by for loop



Code Box by for loop
-----------------------------
/*program to print number pattern by for loop

  1
  22
  333
  4444
  55555

*/

class npat3
{
public static void main(String a[])
{
int n,i,j;

n=Integer.parseInt(a[0]);

for(i=1;i<=n;i++)
{
        for(j=1;j<=i;j++)
        {
        System.out.print(i);
        }

System.out.print("\n");

}
}
}



Publisher: Brijmohan Lal Sahu - 5:08 PM
, , , , , ,

Number Pattern 2 by for loop



Code Box by for loop
--------------------------

/*program to print star pattern by for loop

  1
  12
  123
  1234
  12345

*/

class npat2
{
public static void main(String a[])
{
int n,i,j;

n=Integer.parseInt(a[0]);

for(i=1;i<=n;i++)
{
        for(j=1;j<=i;j++)
        {
        System.out.print(j);
        }

System.out.print("\n");

}
}
}


Publisher: Brijmohan Lal Sahu - 4:40 PM
, , , , , ,

Number Pattern 1 by for loop


Number Pattern
codeboxjava
Code Box by for loop
-------------------------
/*program to print number pattern square box by for loop

  12345
  12345
  12345
  12345
  12345
  
*/

class npat1
{
public static void main(String a[])
{
int n,i,j;

n=Integer.parseInt(a[0]);

for(i=1;i<=n;i++)
{
        for(j=1;j<=n;j++)
        {
        System.out.print(j);
        }

System.out.print("\n");

}
}
}


Publisher: Brijmohan Lal Sahu - 4:08 PM
, , , ,

Program to illustrate Function with return type and arguments in java


Addition of two numbers.

Code Box
-------------------
/*Program for  function with return type and with arguments*/

class funwithr
{
public static void main(String r[])
{
int total,a,b;
a=Integer.parseInt(r[0]);
b=Integer.parseInt(r[1]);

System.out.print("\nSum of two number:");
total=sum(a,b);
System.out.print(total);    //Function call
}
public static int sum(int a,int b)  //Function Definition
{
int c;
c=a+b;
return c;
}


}

Publisher: Brijmohan Lal Sahu - 3:54 PM
, , , , , , ,

Simple Function in java without return type and without arguments


Code Box

Download Link:
Publisher: Brijmohan Lal Sahu - 3:51 PM
, , , , , , ,

Perfect Number Checker Using while loop


Code Box
------------------

/*Program to check input number is 
perfect or not using while loop*/

class per_while
{
public static void main(String a[])
{
int i,j,k,sum,mul;
sum=0;
mul=1;
i=1;
k=Integer.parseInt(a[0]);

while(i<k)
{
if(k%i==0)
{
mul=mul*i;
sum=sum+i;
}
i++;
}

if(sum==mul && k==mul)
{
System.out.println("perfect");
}
else
{
System.out.println("Not perfect");
}
}
}


Publisher: Brijmohan Lal Sahu - 3:38 PM
, , , , , ,

Perfect Number Checker


Code Box

Download Link:
Publisher: Brijmohan Lal Sahu - 3:27 PM
, , , , ,

Program to print number table from 2 to 10


Number Table printing requires a little knowledge of for loop for repeating the chain..

This program print tables for numbers from 2 to 10.

you can also change the range at first outer loop to increase of decrease the range..

Code Box
--------------------
/* A simple program to print Number Table from 2 to 10  */

class table
{
public static void main(String a[])
{
int num,i,j;

System.out.println("--------------------------------------------------------\n");

for(i=2;i&lt;=10;i++)
{
        System.out.print("Table of "+i+" =&gt;"); 
        for(j=1;j&lt;=10;j++)
        {
         num=i*j;
        System.out.print(" | "+num);
        }
System.out.println("\n-------------------------------------------------------\n");

}
}
}


Publisher: Brijmohan Lal Sahu - 3:02 PM

Wednesday, September 18, 2013

, , , , ,

Java Program to print hello your name

It's really exciting for new learner to write her/his own name in new language..
Same thing happen when you learn java and write a program that prints a beautiful line saying hello to your name..

Below code in Code Box takes your name as argument and print hello with your name.
Try it on your computer and try to modify the program by adding some more information about you.

Code Box
//A program to print hello "your_name"

class name
{
public static void main(String a[])
{
String yname;
yname=a[0];

System.out.println("hello "+yname);
}
}


If you want to make it more better do your own experiments!!
Don't limit your self & find some more programs to do...

Just for your  hint!!
Code Box 1
//A program to print hello "your_name" & "city"

class name
{
public static void main(String a[])
{
String yname,city;
yname=a[0];
city=a[1];

System.out.println("hello "+yname);

System.out.println("you are from "+city+", nice to meet you!!");

}
}



Publisher: Brijmohan Lal Sahu - 9:39 AM
, , , , , , , , ,

ASCII to CHARACTER


Code Box

Download Link:
Publisher: Brijmohan Lal Sahu - 9:37 AM