Java Area of rectangle calculator. Please help! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Java Area of rectangle calculator. Please help!

I have no idea how to do this 😬😬 I tried but it never works. "The program you are given takes length and width of a rectangle as input. Complete the method to take them as parameters, then calculate and output the area of the rectangle." import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int width = read.nextInt(); int height = read.nextInt(); printArea(width, height); } public static void printArea() { System.out.println(width*height); } }

11th Jun 2021, 6:35 AM
Jay Kay
9 Answers
+ 4
Emma Watson thank you very much for help! But I don't know why I should write 'int width, int height' again in the method. Isn't it already done from 'printArea(width, height);' in the 'main' method?
11th Jun 2021, 7:07 AM
Jay Kay
+ 3
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int width = read.nextInt(); int height = read.nextInt(); printArea(width, height); } //Please Subscribe to My Youtube Channel //Channel Name: Fazal Tuts4U public static void printArea(int width, int height) { System.out.println(width*height); } }
4th Sep 2021, 4:45 AM
Fazal Haroon
Fazal Haroon - avatar
+ 2
Enter the parameters/function signature in the printArea method as mentioned by Emma Watson
11th Jun 2021, 6:51 AM
Atul [Inactive]
+ 1
Jay Kay You didn't pass parameters in defined method.
11th Jun 2021, 7:03 AM
A͢J
A͢J - avatar
+ 1
Because it is mentioned in the main method to input in int
11th Jun 2021, 7:08 AM
Atul [Inactive]
+ 1
Emma Watson Atul 🅰🅹 🅐🅝🅐🅝🅣 thank you so much for the help! 👍👍
11th Jun 2021, 7:38 AM
Jay Kay
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner width = new Scanner(System.in); Scanner height = new Scanner(System.in); double The_height = height.nextDouble(); double The_width = width.nextDouble(); area(The_width, The_height); } static void area(double width, double height){ System.out.println("area = " + width * height); } }
6th Nov 2021, 6:55 PM
Mohammad Jamal Mahmoud Al Jadallah
Mohammad Jamal Mahmoud Al Jadallah - avatar
0
A rectangle is a four-sided shape with right angles. Its opposite sides have equal length, and diagonals bisect at right angles. Formula: Area = Length * Width Example: Length = 10 Width = 8 Area of Rectangle is 80 Find Area of Rectangle in Java //Area of Rectangle in Java import java.util.Scanner; public class RectangleArea { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the length : "); double length = scanner.nextDouble(); System.out.print("Enter the width : "); double width = scanner.nextDouble(); scanner.close(); // calculate area of rectangle double area = length * width; System.out.println("The area of the rectangle is: " + area); } } Output C:\CodeRevise\java>javac RectangleArea.java C:\CodeRevise\java>java RectangleArea Enter the length : 10 Enter the width : 7 The area of the rectangle is: 70.0 for more java programs kindly visit:- https://coderevise.com/java-programs/
18th Sep 2023, 12:28 PM
Code Revise
Code Revise - avatar
- 1
Jay Kay In main method you are calling that defined method so 1 is defined method and 1 is called method. Both should be same. In calling method we just pass same datatype value in same order in which we have defined. Calling method should be same as defined method otherwise compiler will not understand like If I call you with other name then you can not understand that I am calling you or someone else.
11th Jun 2021, 7:45 AM
A͢J
A͢J - avatar