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

Wednesday, August 15, 2012

CJ-18 : Store n numbers into an Array and print it

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.*;
public class array 
{
   public static void main(String args[]) 
    {
        int a[]=new int[20];
        int i,n;
        try
        {
            DataInputStream x=new DataInputStream(System.in);
            System.out.println("Enter limit value for array");
            n=Integer.parseInt(x.readLine());
            System.out.println("Enter array elements :");
            for(i=0;i<n;i++)
            {
                a[i]=Integer.parseInt(x.readLine());
            }
            System.out.println("array elements are :");
            for(i=0;i<n;i++)
            {
                System.out.println(a[i]);
            }
        }
        catch(Exception e)
        {
        }
    }      
}    
=========================================================================
Output : 

Enter limit value for array
5
Enter array elements :
1
2
3
4
5
array elements are :
1
2
3
4
5

CJ-17: Program to print a pattern

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.
***********************************************************************************************
Program to print a pattern as shown below :
*
* *
* * *
* * * * 
* * * * * 
***********************************************************************************************
import java.io.*;
public class nestedloop 
{
    public static void main(String args[])
    {
        int i,j;
        for(i=0;i<5;i++)
        {
            for(j=0;j<i;j++)
            {
                System.out.print("*");
                System.out.print("  ");
            }
            System.out.println("");
        }
    }  
}
=========================================================================
Output : 
*
* *
* * *
* * * * 
* * * * * 


CJ-16 : Numbers divisible by 7, and its sum(2)

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.*;

public class div1
{
    public static void main(String args[])
    {
        int sum=0,ct=0,n,i;
        try
        {
            DataInputStream s= new DataInputStream(System.in);
            System.out.println("Enter the limit :");
            n=Integer.parseInt(s.readLine());
            System.out.println("Numbers divisible by 7 are :");
            for(i=0;i<n;i++)
            {
                if(i%7==0)
                {
                    System.out.println(i);
                    ct++;
                    sum=sum+i;
                }
            }
            System.out.println("Sum= "+sum);
            System.out.println("Total Numbers divisible by 7 is :"+ct);
        }
        catch(Exception e)
        {
        }
    }
}
=========================================================================
Output :


Enter the limit :
50
Numbers divisible by 7 are :
0
7
14
21
28
35
42
49
Sum= 196
Total Numbers divisible by 7 is :8