Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Showing posts with label core java : while. Show all posts
Showing posts with label core java : while. Show all posts

Monday, August 6, 2012

CJ-14: Sum of the digit of a number

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************
import java.io.*;
class digitsum
{
public static void main(String args[])
{
     int r,sum=0,n;
     try
     {
DataInputStream x=new DataInputStream(System.in);
System.out.println("Enter a number");
n=Integer.parseInt(x.readLine());
while(n>0)
{
   r=n%10;
   sum=sum+r;
   n=(int)(n/10);
}
System.out.println("sum = "+sum);
     }
     catch(Exception e)
     {
     }
}
}
=========================================================================
Output :
Enter a number :
123
sum = 6




Friday, August 3, 2012

CJ-13: Reverse a number

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************
import java.io.*;
class reverse
{
public static void main(String args[])
{
   int r,n;
   int rev=0;
   try
   {
DataInputStream x=new DataInputStream(System.in);
System.out.println("Enter a number :");
n=Integer.parseInt(x.readLine());
while(n>0);
{
   r=n%10;
   rev=rev*10+r;
   n=(int)(n/10);
}
System.out.println("Number Reversed is :"+rev);
    }
    catch(Exception e)
    {
    }
}
}
=========================================================================
Output :
Enter a number :
143
Number Reversed is :
341

Monday, July 30, 2012

CJ-10: Print a message 5 times-While loop

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************
import java.io.*;
class loop1
{
public static void main(String args[])
{
int i=0;
while(i<=4)
{
  System.out.println("Welcome to JAVA");
  i++;
}
}
}
=========================================================================
Output :
Welcome to JAVA
Welcome to JAVA
Welcome to JAVA
Welcome to JAVA