1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
/* Calculate Rectangle Area using Java Example This Calculate Rectangle Area using Java Example shows how to calculate area of Rectangle using it's length and width. */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class CalculateRectArea { public static void main(String[] args) { int width = 0; int length = 0; try { //read the length from console BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Please enter length of a rectangle"); length = Integer.parseInt(br.readLine()); //read the width from console System.out.println("Please enter width of a rectangle"); width = Integer.parseInt(br.readLine()); } //if invalid value was entered catch(NumberFormatException ne) { System.out.println("Invalid value" + ne); System.exit(0); } catch(IOException ioe) { System.out.println("IO Error :" + ioe); System.exit(0); } /* * Area of a rectangle is * length * width */ int area = length * width; System.out.println("Area of a rectangle is " + area); } } /* Output of Calculate Rectangle Area using Java Example would be Please enter length of a rectangle 10 Please enter width of a rectangle 15 Area of a rectangle is 150 */ |
excellent man………….
Very useful programs.Excellent for practice. Thank you.
great, nice, wonder e’n Excellent 4 practices.
very good. thank you
do you have other programs made using JOptionPane?
I am pretty sure this could be easily made using JOptionPane, but then again knowing different ways to do stuff is helpful. Cheers.
What is the difference between buffered reader, JOptionPane and Scanner?
I always use JOptionPane and Scanner.. what difference does it make using buffered reader?
It’s for a square
HELPFUL…………..FOR STUDIOUS..LOOOLOLLLLLLLL