|
|
Acquisire da linea di comando “cognome”, “nome” e “età” di una persona if(args.length != 3)
return;
String cognome=args[0],
nome=args[1];
int età=Integer.parseInt(args[2]);
Se l’età non è almeno 18 settarla a 18 if(età < 18) età=18; Se l’età è minore di 0 chiederne l’inserimento all’utente if(età < 0)
{
ConsoleReader tastiera = new ConsoleReader();
System.out.print("Inserisci l'età: ");
età=tastiera.readInt();
}
Se l’età è pari creare un array contenente 100 numeri casuali compresi tra 0 e l’età e visualizzarlo if(età%2 == 0)
{
int[] centonumeri=new int[100];
for(int i=0; i < 100; i++)
centonumeri[i]=(int)(età*Math.random());
for(int i=0; i < 100; i++)
System.out.print(centonumeri[i] + "\t");
}
Se l’età è dispari e minore di 50 visualizzarne, separate, le cifre delle decine e delle unità. if(età%2 != 0 && eta < 50) System.out.print(età/10 + ", " + età%10); In definitiva, adattando il codice dove possibile class Compito24092004
{
public static void main(String[] args)
{
if(args.length != 3)
return;
String cognome=args[0],
nome=args[1];
int età=Integer.parseInt(args[2]);
if(età >= 0 && età < 18)
età=18;
else if(età < 0)
{
ConsoleReader tastiera=new ConsoleReader();
System.out.print("Inserisci l'età: ");
età=tastiera.readInt();
}
if(età%2 == 0)
{
int[] centonumeri=new int[100];
for(int i=0; i < 100; i++)
centonumeri[i]=(int)(età*Math.random());
for(int i=0; i < 100; i++)
System.out.print(centonumeri[i] + "\t");
}
else if(età < 50)
System.out.print(età/10 + ", "+età%10);
}
}
|
|