Posts

Showing posts from July, 2011

find area of an components

//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...

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(); } }

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 pro...