mardi 25 février 2020

Coding the Pythagoras theorem

Hi I am a beginner at java and I'm trying to write code to solve the Pythagoras' theorem. Here's what I've done so far however I keep getting errors with an illegal starter on line 14 as well as a "class, interface, or enum expected" error on line 31.

public class Pythagoras{

    public static void main(String[] args){
        double a1 = 5.2;
        float a = (float)a1;
        double b1 = 8.4;
        float b = (float)b1;
        double c1 = 0;
        float c = (float)c1;

        float resultC = (float)method (c);
        System.out.println(resultC);

        public static float method(float c){
            if (c = 0){
            float result = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
            return result;
            }

            if (b = 0){
            float result = Math.sqrt(Math.pow(c, 2) - Math.pow(a, 2));
            return result;
            }

            if (a = 0){
            float result = Math.sqrt(Math.pow(c, 2) - Math.pow(b, 2));
            return result;
            }
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire