Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.Math;
- import javax.swing.JOptionPane;
- class pitagoras2{
- public static void main(String[] args) {
- int num;
- String num1, num2, num3;
- double c1, c2, total, hipotenusa;
- num = Integer.parseInt(JOptionPane.showInputDialog("1 - Sabendo os Dois catetos\n"
- + "2 - Sabendo apenas um cateto e a hipotenusa: "));
- switch(num){
- case 1:
- num1 = JOptionPane.showInputDialog("Primeiro cateto");
- num2 = JOptionPane.showInputDialog("Segundo cateto");
- c1 = Double.parseDouble(num1);
- c2 = Double.parseDouble(num2);
- c1 = c1 * c1;
- c2 = c2 * c2;
- total = c1+c2;
- hipotenusa = (double) Math.sqrt(total);
- JOptionPane.showMessageDialog(null, "Hipotenusa: " + hipotenusa);
- break;
- case 2:
- num1 = JOptionPane.showInputDialog("Cateto conhecido: ");
- num2 = JOptionPane.showInputDialog("Hipotenusa: ");
- c1 = Double.parseDouble(num1);
- c2 = Double.parseDouble(num2);
- c1 = c1 * c1;
- c2 = c2 * c2;
- if (c1 > c2){
- total = c1 - c2;
- hipotenusa = (double) Math.sqrt(total);
- JOptionPane.showMessageDialog(null, "Cateto desconhecido: " + hipotenusa);
- }
- else{
- total = c2 - c1;
- hipotenusa = (double) Math.sqrt(total);
- JOptionPane.showMessageDialog(null, "Cateto desconhecido: " + hipotenusa);
- }
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement