C.I.A.EMO.BOYS
Ominide
1 min. di lettura
Vota 3 / 5

Sottoprogramma:

import java.io.BufferedReader;
import java.io.InputStreamReader;
public class TriangoloRettangolo
{
float cateto1,cateto2;
public TriangoloRettangolo()
{
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader tastiera = new BufferedReader(input);
System.out.print("cateto1: ");
try
{
String numeroLetto = tastiera.readLine();
cateto1 = Integer.valueOf(numeroLetto).intValue();
}
catch(Exception e){}
System.out.print("cateto2: ");
try
{
String numeroLetto = tastiera.readLine();
cateto2 = Integer.valueOf(numeroLetto).intValue();
}
catch(Exception e){}
}
public double Ipotenusa ()
{
double Ipo;
Ipo = (Math.sqrt(Math.pow(cateto1,2)+Math.pow(cateto2,2)));
return Ipo;
}
}

------------------------------------------------------------------------------------------------
programma principale:

public class ProgTriangoloRettangolo
{
public static void main(String[] args)
{
TriangoloRettangolo objTrRett;
objTrRett = new TriangoloRettangolo();
System.out.println("Ipotenusa= "+objTrRett.Ipotenusa());
}
}

Domande e risposte

Hai bisogno di aiuto?
Chiedi alla community