programmazione-java/src/RettangoloDaTastiera.java

30 lines
978 B
Java
Raw Normal View History

2016-10-10 15:10:32 +00:00
import java.awt.Rectangle;
import java.util.Scanner;
public class RettangoloDaTastiera{
public static void main(String[] arg){
2016-10-10 21:34:30 +00:00
Rectangle ret, retMax=null;
int i=0, imax=0;
Scanner in = new Scanner(System.in);
2016-10-10 15:10:32 +00:00
2016-10-10 21:34:30 +00:00
System.out.println("Inserisci la x, la y, la larghezza e l'altezza: ");
ret = new Rectangle(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt());
2016-10-10 15:10:32 +00:00
2016-10-10 21:34:30 +00:00
while(ret.getX()!=0 || ret.getY()!=0 || ret.getWidth()!=0 || ret.getHeight()!=0){
i++;
if(retMax==null || ret.getWidth()*ret.getHeight()>retMax.getWidth()*retMax.getHeight()){
retMax=ret;
imax=i;
}
System.out.println("Inserisci la x, la y, la larghezza e l'altezza: ");
ret = new Rectangle(in.nextInt(), in.nextInt(), in.nextInt(), in.nextInt());
2016-10-10 15:10:32 +00:00
}
2016-10-10 21:34:30 +00:00
if(retMax==null)
System.out.println("IMPOSSIBILE ESEGUIRE L'OPERAZIONE.\nSono stati inseriti zero rettangoli");
else
System.out.println("Il "+imax+"° rettangolo ha l'area massima");
2016-10-10 15:10:32 +00:00
}
}