Answer to Question #251742 in Java | JSP | JSF for guru

Question #251742

Write a java program that specifies three parallel one dimensional arrays name length, width, and area. Each array should be capable of holding a number elements provided by user input. Using a for loop input values for length and width arrays. The entries in the area arrays should be the corresponding values in the length and width arrays (thus, area[i] = length [i]* width [i]) after data has been entered display the following output:


Length Width Area


-------- -------- -------


25 2.6 65.00


18.2 4.9 89.18


Sample Run1


Enter the array size: 5


Enter the Length and Width for Rectangle 1: 25 2.6


Enter the Length and Width for Rectangle 2: 18 4.9


Enter the Length and Width for Rectangle 3: 100 3.27


Enter the Length and Width for Rectangle 4: 1.84 7.4


Enter the Length and Width for Rectangle 5: 56 9.5


1
Expert's answer
2021-10-16T01:44:02-0400

Source code

import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
	    Scanner in=new Scanner(System.in);
	    int n;
	    System.out.print("Enter the array size: ");
	    n=in.nextInt();
		double [] length=new double [n];
		double [] width=new double [n];
		double [] area=new double [n];
		for(int i=0;i<n;i++){
		    System.out.print("Enter the Length and Width for Rectangle "+(i+1)+": ");
		    length[i]=in.nextDouble();
		    width[i]=in.nextDouble();
		    area[i]=length[i]*width[i];
		}
		System.out.println("Length\tWidth\tArea");
		System.out.println("------\t-----\t----");
		for(int i=0;i<n;i++){
		    System.out.println(length[i]+"\t"+width[i]+"\t"+area[i]);
		}
	}
}


Output





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS