write a program to print area of rectangle. take input from user
Answers
Answered by
32
♥♥
import java.util.Scanner;
public class Main {
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
int length = sc.nextInt();
int breadth = sc.nextInt();
System.out.println("Area of the rectangle is : " + (length * breadth));
}
}
♥♥
- Line 1 - Imports Scanner class for input.
- Line 2 - Declares class Main.
- Line 3 - Main method.
- Line 4 - Activation of Scanner.
- Line 5 - Gets 1st input.
- Line 6 - Gets 2nd input.
- Line 7 Prints the area.
♥♥
length = int(input())
breadth = int(input())
print("Area of the rectangle is : " + str(length * breadth))
♥♥
- Line 1 - Gets 1st input.
- Line 2 - Gets 2nd input.
- Line 3 - Prints the area.
♥♥
#include <iostream>
using namespace std;
int main() {
int length, breadth;
cin >> length;
cin >> breadth;
cout << "Area of rectangle is : " << (length * breadth);
return 0;
}
♥♥
- Line 1 - Includes the header file.
- Line 2 - Declares that we are using standard namespace.
- Line 3 - White space.
- Line 4 - Main method.
- Line 5 - Declaration of variables in which the input is to be taken.
- Line 6 - Gets 1st input.
- Line 7 - Gets 2nd input.
- Line 8 - Prints the area.
- Line 9 - Required at the end of every C++ program.
Hope it helps..♪
Attachments:
Similar questions