Search This Blog

If you like any posts in this blog then click this icon which is present under the post
Showing posts with label Java Programs. Show all posts
Showing posts with label Java Programs. Show all posts

Monday, 10 October 2011

Program for Hormonic series

Program
import java.io.*;
class HormonicSeries
{
    public static void main(String args[])
    {
        float s=0f;int n=0;
        try
        {

Sunday, 31 July 2011

Program to Implement abstract class


import java.io.*;
import java.util.*;
abstract class Employee
{
            private String name;
            private int ssn;
            Employee(String s,int a)
            {
                        setname(s);
                        setssn(a);
                        getname();
                        getssn();

Program to Implement Multilevel Inheritance


import java.io.*;
class Point
{
            protected double x,y;
            Point(double a,double b)
            {
                        setpoint(a,b);
                        getx();
                        gety();

Monday, 25 July 2011

Program to Demonstrate switch case in Java

import java .io.*;
class switch
{
public static void main(Strings args[])
{
for (int i=o;i<4;i++)
{
switch(i)
{
case 0: if(i<1)
                        System.out.println(+i+”less than”+1);
            case 1: if(i<2)
                        System.out.println(+i+”less than”+2);

Monday, 18 July 2011

Program to Return the Object to main class in Java

     This program returns the object to the main class from the sub class.

import java.io.*;
class robject
{
int a;
robject(int x)
{

Program to implement final Keyword in Java

 This program is used to implement final variable. Final variable is constant variable which is unchanged. 

import java.io.*;
import java.util.*;
class increment
{
private int i;
private final int J;
increment()
{
J=2;  // final value

Program to Demonstrate Static & this Keyword


     This program is used to demonstrate static variable, static member and this keyword.

import java.io.*;
import java.util.*;
class Employee
{
            String fn,ln;
            static int count=0; 
            Employee( String s,String s1)
            {

Program to Implement Method Overloading in Java


     This is a program to implement method overloading which passes the integer,float,double variable as a argument.

import java.io.*;
import java.util.*;
class Method1
{
            void add(int a,int b)
            {

Program to Implement Constructor Overloading in Java


     This program is used to implement constructor overloading. Here the integer, float, double variable and object is passed as arguments.
 
import java.io.*;
import java.util.*;
class Box1
{
            int wt,ht,dt,a;
            float wt1,ht1,dt1,a2;
            double wt2,ht2,dt2,a3;
            Box1()

Program to Implement Stack in Java


    This program is used to demonstrate the Stack operations PUSH & POP with the help of Switch an if statements.


import java.io.*;

import java.util.*;

class Stack

{

    int a[]=new int[10];

    int top=0;

    Stack()

Wednesday, 13 July 2011

Program to demonstrate the Switch case and If statement


This a Program to demonstrate the Switch case and If statement by calculating the discount amount of a cloth products

Program:
 
import java.io.*;
import java.util.*;
class Cloth1
{
void purchase()
                {
                Scanner s=new  Scanner(System.in);
                System.out.println("What do  you want to Purchase? \n 1)Mill Cloth \n 2)Handloom Cloth \n 3)Exit");

Monday, 4 July 2011

Program to Implement Number Pattern in Java

class Pattern
{
                public static void main(String args[])
                {
                                int twod[][]=new int[4][];
                                twod[0]=new int[1];
                                twod[1]=new int[2];
                                twod[2]=new int[3];
                                twod[3]=new int[4];

Program to Implement Library Funtions in Java


import java.io.*;
import java.math.*;
class three
{
                public static void main(String args[])
                {
                                System.out.println("Square Root of 44 is "+Math.sqrt(44));
                                System.out.println("Sin of 90 is "+Math.sin(90));
                                System.out.println("Cos of 0 is "+Math.cos(0));
                                System.out.println("Tan of 45 is "+Math.tan(45));

Friday, 1 July 2011

Program for Type Conversion in Java

import java.io.*;
class Typeconversion
{
    public static void main(String args[])
    {
        double i;
        float sum1=0.0f,sum=0.0f;
        for(i=1;i<=20;i++)
        {
            sum1=(float)i;
            sum+=(1/sum1);

Program for Escape Sequence in Java

import java.io.*;
class Escape
{
    public static void main(String args[])
    {
        System.out.println("P    Q    P&Q    P|Q      P^Q");
        int i,x,y,z;
        int p[]={0,0,1,1};
        int q[]={0,1,0,1};
        for(i=0;i<4;i++)

Program for Gallons to Liter Conversion in java

import java.io.*;
class Conversion
{
    public static void main(String args[])
    {
        double ans;
        for(int i=1;i<=20;i++)
        {
            ans=i*3.84;

Program for Display Alphabets & Sorted Numbers in Java

import java.io.*;
class Alpha
{
    public static void main(String args[])
    {
        String s[]={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
        int n=s.length;
        for(int i=0;i<n;i++)
        {
            System.out.print(s[i]);
        }
        int s1[]={1,54,26,8,32,65};
        int n1=s1.length;

Followers