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
5 ответов
+ 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
+ 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
}
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);
}
}
0
Have inserted loop.
0
Thanks ,it runs now.
But it multiplies the code by (i<=10) In the loop.