How to writes a Scanner java program that will calculate the area of a rectangle 10 times. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to writes a Scanner java program that will calculate the area of a rectangle 10 times.

That will allow the user to insert the integer 10 times

4th Dec 2020, 6:18 PM
HABEEB
5 Answers
+ 1
1. Make a function that calculates the area when dimesions are given to it as arguments 2. Make a for loop that executes 10 times 3. Inside the for loop body, ask for input, parse the input and pass as arguments to the function you created. Output the result to the screen
4th Dec 2020, 6:22 PM
XXX
XXX - avatar
+ 1
The for loop body is empty. Enclose the code after the for statement in curly braces and remove the semicolon after the for statement for (Y=1; Y<=10; Y=Y+1) { // rest of the code here }
4th Dec 2020, 8:02 PM
XXX
XXX - avatar
0
import java.util.Scanner; public class Scannerinput { public static void main(String[] args) { int U; int Y; for(Y=1;Y<=10;Y=Y+1); Scanner input= new Scanner(System.in); System.out.println("LENGHT:"); int L = input.nextInt(); System.out.println("BREADTH:"); int B = input.nextInt(); U = L*B; System.out.println("The area of rectangle is:"+U+Y); } }
4th Dec 2020, 6:45 PM
HABEEB
0
Have inserted loop.
4th Dec 2020, 6:45 PM
HABEEB
0
Thanks ,it runs now. But it multiplies the code by (i<=10) In the loop.
4th Dec 2020, 9:44 PM
HABEEB