To find area of rectangle

IN THIS PROGRAM VALUES WILL BE TAKEN  FROM USER

PROGRAM : 

1. USING SCANNER :

import java.util.Scanner;
class AreaR
{
public static void main( String [] args)
{
int l,b,c=0;
System.out.println("Enter the length and breadth of rectangle");
Scanner s = new Scanner(System.in);
l = s.nextInt();
b= s.nextInt();
System.out.println("the length and breadth given by you  are :"+l +b);
c= l*b;
System.out.println("The are of rectangle is:"+c);
}
}

2. USING JAVA SWING

import javax.swing.*;
class AreaR
{
public static void main (String [] args)
{
String s,v ; 
int l,b,c=0;
s = JOptionPane.showInputDialog("Enter the length of rectangle");
l= Integer.parseInt(l);
v = JOptionPane.showInputDialog("Enter the breadth of rectangle");
b= Integer.parseInt(v);
c = l*b;
JOptionPane.showMessageDialog("The area of rectangle is :"+c);
}
}








No comments:

Post a Comment