//area1.java
import java.io.*;
class area
{
int x;
double y;
void cal(double pi,int ra)
{
y = pi*ra*ra;
System.out.println("Circle area is\t:"+y);
}
void cal(int len)
{
x = len*len;
System.out.println("Squre area is\t:"+x);
}
void cal(int len,int br)
{
x = len*br;
System.out.println("Rectangle area is\t:"+x);
}
}
class area1
{
public static void main(String args[])throws IOException
{
DataInputStream in = new DataInputStream(System.in);
System.out.print("choose any one \t 1.CIRCLE \t 2.SQURE \t 3.RECTANGLE\t:");
int a = Integer.parseInt(in.readLine());
area A = new area();
if(a==1)
{
System.out.print("Enter the radius\t:");
int b = Integer.parseInt(in.readLine());
A.cal(3.14,b);
}
else if(a==2)
{
System.out.print("Enter the length\t:");
int c = Integer.parseInt(in.readLine());
A.cal(c);
}
else
{
System.out.print("Enter the length\t:");
int d = Integer.parseInt(in.readLine());
System.out.print("Enter the breath\t:");
int e = Integer.parseInt(in.readLine());
A.cal(d,e);
}
}
}
Thursday, July 21, 2011
program using abstract
//abstractdemo.java
abstract class Shape
{
int x,y;
void getdata(int x1,int y1)
{
x=x1;
y=y1;
}
abstract void area();
}
class Rectangle extends Shape
{
void area()
{
int a=x*y;
System.out.println("Area of Rectangle having width"+x+"and Height="+y+"is"+a);
}
}
class Triangle extends Shape
{
void area()
{
int a=(x*y)/2;
System.out.println("Area of Triangle="+a);
}
}
class AbstractDemo
{
public static void main(String arg[])
{
Rectangle r=new Rectangle();
r.getdata(20,10);
r.area();
Triangle t=new Triangle();
t.getdata(30,40);
t.area();
}
}
abstract class Shape
{
int x,y;
void getdata(int x1,int y1)
{
x=x1;
y=y1;
}
abstract void area();
}
class Rectangle extends Shape
{
void area()
{
int a=x*y;
System.out.println("Area of Rectangle having width"+x+"and Height="+y+"is"+a);
}
}
class Triangle extends Shape
{
void area()
{
int a=(x*y)/2;
System.out.println("Area of Triangle="+a);
}
}
class AbstractDemo
{
public static void main(String arg[])
{
Rectangle r=new Rectangle();
r.getdata(20,10);
r.area();
Triangle t=new Triangle();
t.getdata(30,40);
t.area();
}
}
Saturday, July 16, 2011
Addition of two numbers
import java.io.*; //import java.io package
import java.lang.*; //import java.lang package
class add
{
public static void main(String args[])throws IOException
{
DataInputStream in = new DataInputStream(System.in);
int a=0;
int b=0;
a = Integer.parseInt(in.readLine());
b = Integer.parseInt(in.readLine());
int d = a+b;
System.out.println(d);
}
}
/*package contain classes and methods*/
Description:
1. uses of static
we cannot call any instance method without create a any instance to the class..at the time of program starts we cant have any instance,bcos java is object oriented so only
declaration of main also require one class...static can used to compile without have an object
2. java is case sensitive
we need to specify correctly class name,and methods
3.input metods
i thing in java various way to get input from console..
=> using Scanner class
=> using BufferedDeader class
=> using command line arguments args[0],args[1],etc
=> using datainputstream class
in this program we can use datainputstream class
its under the package of java.io.datainputstream;
the input read from the console is string , so if we need other type we can convert the string using the following methods.
1.integer.parseInt(string)
we "in" is a object for datainputstream class,using this object to call the method readLine() = read from the console and return the string
>javap java.io.DataInputStream
Compiled from "DataInputStream.java"
public class java.io.DataInputStream extends java.io.FilterInputStream implements java.io.DataInput{
public java.io.DataInputStream(java.io.InputStream);
public final int read(byte[]) throws java.io.IOException;
public final int read(byte[], int, int) throws java.io.IOException;
public final void readFully(byte[]) throws java.io.IOException;
public final void readFully(byte[], int, int) throws java.io.IOException;
public final int skipBytes(int) throws java.io.IOException;
public final boolean readBoolean() throws java.io.IOException;
public final byte readByte() throws java.io.IOException;
public final int readUnsignedByte() throws java.io.IOException;
public final short readShort() throws java.io.IOException;
public final int readUnsignedShort() throws java.io.IOException;
public final char readChar() throws java.io.IOException;
public final int readInt() throws java.io.IOException;
public final long readLong() throws java.io.IOException;
public final float readFloat() throws java.io.IOException;
public final double readDouble() throws java.io.IOException;
public final java.lang.String readLine() throws java.io.IOException;
public final java.lang.String readUTF() throws java.io.IOException;
public static final java.lang.String readUTF(java.io.DataInput) throws java.io.IOException;
}
system.out.print - for printing continiously
system.out.println - for printing line by line
import java.lang.*; //import java.lang package
class add
{
public static void main(String args[])throws IOException
{
DataInputStream in = new DataInputStream(System.in);
int a=0;
int b=0;
a = Integer.parseInt(in.readLine());
b = Integer.parseInt(in.readLine());
int d = a+b;
System.out.println(d);
}
}
/*package contain classes and methods*/
Description:
1. uses of static
we cannot call any instance method without create a any instance to the class..at the time of program starts we cant have any instance,bcos java is object oriented so only
declaration of main also require one class...static can used to compile without have an object
2. java is case sensitive
we need to specify correctly class name,and methods
3.input metods
i thing in java various way to get input from console..
=> using Scanner class
=> using BufferedDeader class
=> using command line arguments args[0],args[1],etc
=> using datainputstream class
in this program we can use datainputstream class
its under the package of java.io.datainputstream;
the input read from the console is string , so if we need other type we can convert the string using the following methods.
1.integer.parseInt(string)
we "in" is a object for datainputstream class,using this object to call the method readLine() = read from the console and return the string
>javap java.io.DataInputStream
Compiled from "DataInputStream.java"
public class java.io.DataInputStream extends java.io.FilterInputStream implements java.io.DataInput{
public java.io.DataInputStream(java.io.InputStream);
public final int read(byte[]) throws java.io.IOException;
public final int read(byte[], int, int) throws java.io.IOException;
public final void readFully(byte[]) throws java.io.IOException;
public final void readFully(byte[], int, int) throws java.io.IOException;
public final int skipBytes(int) throws java.io.IOException;
public final boolean readBoolean() throws java.io.IOException;
public final byte readByte() throws java.io.IOException;
public final int readUnsignedByte() throws java.io.IOException;
public final short readShort() throws java.io.IOException;
public final int readUnsignedShort() throws java.io.IOException;
public final char readChar() throws java.io.IOException;
public final int readInt() throws java.io.IOException;
public final long readLong() throws java.io.IOException;
public final float readFloat() throws java.io.IOException;
public final double readDouble() throws java.io.IOException;
public final java.lang.String readLine() throws java.io.IOException;
public final java.lang.String readUTF() throws java.io.IOException;
public static final java.lang.String readUTF(java.io.DataInput) throws java.io.IOException;
}
system.out.print - for printing continiously
system.out.println - for printing line by line
Subscribe to:
Posts (Atom)
உப்பு மாங்காய்
சுருக்குப்பை கிழவி. சுருக்கங்கள் சூழ் கிழவி. பார்க்கும் போதெல்லாம் கூடையுடனே குடியிருப்பாள். கூடை நிறைய குட்டி குட்டி மாங்காய்கள். வெட்டிக்க...
-
கந்தன் வேலைக்குச் சென்று கிட்டத்தட்ட பத்து ஆண்டுகளுக்கு பிறகு சொந்த ஊர் திரும்பி இருந்தான். காளிக் கோயிலைத் தாண்டி தான் அவன் வீட்ட...
-
பிரேமாவின் மூத்த ஆண் குழந்தைக்கு முன் பிறந்த இளைய பெண் குழந்தை அவள். வயலும் சேறும் இரண்டற கலந்த ஊர். முழுதாய் மூன்றாம் வகுப்பைத் ...