Question

Op o rectate input v ;da-lion s: 3 es must be between 0-5o inches ont e어 to be display.x on the screen and sery to an outr^-
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

import java.io.FileWriter;
import java.util.Scanner;
public class Rectangle {
   public static void main( String[] args )
   {
       float Length, Width, Area;
       float []lengtharray = new float[10];
       float []widtharray = new float[10];
       float []areaarray = new float[10];
       StringBuilder sb =new StringBuilder();
Scanner reader = new Scanner(System.in);
       for(int i=0;i<10;i++) {              
   System.out.print("Enter Length of Rectangle "+(i+1)+": ");
   Length = reader.nextFloat();
   lengtharray[i]=Length;
   System.out.print("Enter Width of Rectangle "+(i+1)+": ");
   Width = reader.nextFloat();  
   widtharray[i]=Width;
   Area = Length * Width;
   areaarray[i]=Area;     
       }
       System.out.println("\nRectangle\tLength\tWidth\tArea");
       sb.append("Rectangle\tLength\tWidth\tArea\n");
       float minArea=areaarray[0];
       float maxArea=areaarray[0];
       int minIndex=0,maxIndex=0;
       for(int i=0;i<10;i++) {
           if(minArea > areaarray[i]) {
               minArea = areaarray[i];
               minIndex=i;
           }
           if(maxArea < areaarray[i]) {
               maxArea = areaarray[i];
               maxIndex=i;
           }
          
           System.out.println(" "+(i+1)+"\t\t"+lengtharray[i]+"\t"+widtharray[i]+"\t"+areaarray[i]);
           //sb+=
           sb.append(" "+(i+1)+"\t\t"+lengtharray[i]+"\t"+widtharray[i]+"\t"+areaarray[i]+"\n");
       }      
       System.out.println("Largest Rectangle: "+(maxIndex+1)+". Area: "+maxArea);
       System.out.println("Smallest Rectangle: "+(minIndex+1)+". Area: "+minArea);
       sb.append("Largest Rectangle: "+(maxIndex+1)+". Area: "+maxArea+"\n");
       sb.append("Smallest Rectangle: "+(minIndex+1)+". Area: "+minArea+"\n");
      
       try{
   FileWriter fw=new FileWriter("D:\\testout.txt");
   fw.write(sb.toString());
   fw.close();
   }catch(Exception e){System.out.println(e);}
   }
}

Output:

Enter Length of Rectangle 1: 20 Enter Width of Rectangle 1 30 Enter Length of Rectangle 2: 10 Enter Width of Rectangle 2: 20

Rectangle Length Width Area 20.0 30.0 600.0 10.0 20.0 200.0 15.0 10.0 150.0 Largest Rectangle: 1. Area: 600.0 Smallest Rectan

Add a comment
Know the answer?
Add Answer to:
Op o rectate input v ;da-lion s: 3 es must be between 0-5o inches ont e어 to be display'.x on the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT