Showing posts with label code box java. Show all posts
Showing posts with label code box java. Show all posts

Saturday, November 15, 2014

, , , , , ,

Program to swap two values using third variable in java.

Swapping using third variable


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

/*program to swap two values using third variable */

import java.io.*;

class swap
{
public static void main(String x[]) throws IOException
{
int a,b,temp;

BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));

System.out.print("\nEnter two numbers :");
System.out.print("\nEnter first number a= ");
a=Integer.parseInt(obj.readLine());

System.out.print("\nEnter second number b= ");
b=Integer.parseInt(obj.readLine());

System.out.print("\nValues before swapping a= "+a+" & b= "+b);

temp=a;   //swapping
a=b;
b=temp;

System.out.print("\nValues after swapping a= "+a+" & b= "+b);

}
}



Publisher: Brijmohan Lal Sahu - 10:14 AM

Sunday, November 2, 2014

, , , ,

Program to find factor of any number using command line argument.





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

/* Program to find factor of any number using command line argument */

class factor
{
public static void main(String x[])
{
int num,i;
System.out.print("\n---------Factor Finder--------");
num=Integer.parseInt(x[0]);
System.out.print("\nYou have enter :"+num);

System.out.print("\nFactors of "+num+" are : ");
for(i=1;i<num;i++)
{
if(num%i==0)
{
System.out.print("  "+i);
}

}

}
}



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

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 find area of circle using command line argument.



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

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

class areac
{
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*r*r;

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



}
}

Publisher: Brijmohan Lal Sahu - 3:15 AM

Saturday, November 1, 2014

, , ,

Number Pattern 6 by while loop


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

  55555
  44444
  33333
  22222
  11111
  

*/

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

n=Integer.parseInt(a[0]);
i=n;
while(i>=1)
{j=1;
        while(j<=n)
        {
        System.out.print(i);
        j++;
}

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


Publisher: Brijmohan Lal Sahu - 12:51 AM
, ,

Number Pattern 7 by do while loop


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

  1
  21
  321
  4321
  54321

*/

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

do
{j=i;
        do
        {
        System.out.print(j);
        j--;
}
while(j>=1);
System.out.print("\n");
i++;
}
while(i<=n);
}


}



Publisher: Brijmohan Lal Sahu - 12:35 AM

Thursday, October 30, 2014

, ,

Number Pattern 9 by while loop

CODE BOX
-----------------------------------------------------


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

        1
       12
      123
     1234
    12345

*/

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

while(i<=n)
{j=n;
k=1;
        while(j>i)
        {
        System.out.print(" ");
        j--;
 }

        while(k<=i)
        {
        System.out.print(k);
 k++;
        }
System.out.print("\n");
i++;
}
}
}

Publisher: Brijmohan Lal Sahu - 5:55 AM

Sunday, September 22, 2013

, , , , , ,

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 iluustrate use of Break & Continue in java


Code Box
--------------------
/*Program to print table of all odd numbers less than 10. Useing flowcontrol
terms  Break & Continue. */

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

for(a=1;;a++)
{

if(a>=10)
{ break;
}
else
if(a%2==0)
{continue;
}
else
{
for(b=1;b<=10;b++)
{
System.out.print("  "+b*a);
}

}

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


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

Program to show solution of FizzBuzz Problem


Code Box
------------------------
/* FizzBuzz Program */
/*It prints number from 1 to 50 
=>In place of multiple of 3 it print Fizz
=>In place of multiple of 5 it print Buzz
*/

class fizzbuzz
{

public static void main(String a[])
{
int i;

for(i=1;i<=50;i++)
{
if(i%(3*5)==0)
{
System.out.print("BuzzFizz");
}
else if(i%5==0)
{
System.out.print("Buzz");
}
else if(i%3==0)
{
System.out.print("Fizz");
}
else
{
System.out.print(i);
}

if(i%10==0)
{
System.out.println("\n");
}
else
{
System.out.print("\t");
}
}
}
}



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

Perfect Number Checker


Code Box

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

Program for Character case converter.


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


/* program to Check in put character is Lower or upper case and convert them into other */
class uporlo
{
public static void main(String a[])
{

int i;
char c;

c=a[0].charAt(0);
i=c;

if(i>=97 && i<=122)
{
System.out.println("Enterd Character is Lower Case :"+c);
i=i-32;
c=(char)i;
System.out.println(" Upper case  Character is:"+c);

}
else if(i>=65 && i<=90)
{
System.out.println("Enterd Character is Upper Case :"+c);
i=i+32;
c=(char)i;
System.out.println(" Lower Case  Character is:"+c);

}
else
{
System.out.println("pleas enter a correct case Character");

}
}
}


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

Program for Upper Case Character to Lower Case Character Converter


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

/* program to Convert Upper Character to Lower Character */

class uptolo
{
public static void main(String a[])
{

int i;
char c;

c=a[0].charAt(0);
i=c;

if(i>=65&&i<=80)
{
System.out.println("Enterd Character is :"+c);
i=i+32;
c=(char)i;

System.out.println(" Lower  Character is:"+c);
}
else
{
System.out.println("pleas enter a correct case Character");

}
}
}

Publisher: Brijmohan Lal Sahu - 3:13 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

, , , , , , , , ,

ASCII to CHARACTER


Code Box

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

Program to convert characters in to ASCII values

It's very common program to convert entered characters into their ASCII values.
ASCII means American Standard Code For Information Interchange a special numerical values assigned to every type of visible & non-visible characters of computer.
You can find a complete table of ASCII values here..
ASCII Table


And More details about ASCII here!!

This program Converts any Character into its equivalent ASCII value..

Code Box
// program to print ASCII value of any character enter by user

class ascii
{
public static void main(String a[])
{

int i;
char c;

c=a[0].charAt(0); //marker 1
i=c;


System.out.println("Enterd character is:"+a[0]);
System.out.println("    ASCII value is :"+i);

}

}



//marker 1 : charAt() java built in function that capture a character from a string 
               Syntax: char variable=string.charAt(position);
              Where  #string is any string from which you want to to capture the character
                       # position a numerical value or position of character in string

Note: java takes everything as String. In above program a[0] means 0th argument and charAt(0) means its first character always.


To run this program in Command Prompt :

C:\User>javac ascii.java
C:\User>java ascii h


Out Put: 
Entered character is: h
ASCII value is : 104


Try it!!

If you have any query than feel free to write me. Your are also welcome for any advice & suggestions
make learning more better..
Publisher: Brijmohan Lal Sahu - 9:34 AM
, , , , , , ,

Learning Java programming....

All most every running device online or offline uses java one of the most demanding programming language. In all fields networking, software interface, application design, animation, security and operating systems.

Java if fully object oriented programming language provide an extraordinary powerful environment to developers & designers to convert idea into codes.

May be you don't know about java, But I am sure you know about Android another most popular word in market and Android is build in java.
And this is a Big reason why you need to know about java.

Android comes with a huge opportunity for those programmer & designer who know java to develop android applications, games & a lot more.  

Learning java is really simple & very interesting too. I have a good collection of java programs in very simple programming complexity & if you want to learn, than start from here..
I bet you after you finish basics of java android becomes much & more simple & easy for you.


Let's start with most basic program called say hello to java..


Code Box
//Program to print hello in java

class hello
{
public static void main(String a[])
{
System.out.println("hello to JAVA");
}
}

Publisher: Brijmohan Lal Sahu - 8:55 AM