Computer Notes, Programming codes, Hardware and Networking Tip, Entertainment, Biography, Internet Tip, Tech News, Latest Technology, YouTube,

Write a Java program to create Rectangle class with data member length and breadth. Include methods getData() and displayArea() in the class. Finally create an object of Rectangle class and display its area.



12345678910111213141516171819202122232425262728 

import java.util.Scanner; 
class Rectangle4{
	int l, b; 
	void getData(){
		Scanner in = new Scanner(System.in); 
		System.out.print("Enter length : "); 
		l=in.nextInt(); 

		System.out.print("Enter breadth : "); 
		b=in.nextInt(); 
	}

	void displayArea(){
		int a; 
		a = l*b; 
		System.out.println("Area = "+a); 
	}

	public static void main(String args[]){
		Rectangle4 obj = new Rectangle4();
		obj.getData(); 
		obj.displayArea();  
	}
}


Post a Comment

Emoticon
:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.
disqus
facebook

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget