Wątek przeniesiony 2014-03-23 11:17 z Java przez bogdans.

Sprawdzanie czy trójkąt jest prostokątny

0

Witam, chcę aby program pobierał 3 liczby i sprawdzał czy trójkąt jest prostokątny, pomożecie ?

import java.io.*;
class troj
{
    public static void main(String args[]) throws IOException
    {
        int a1,b1,c1;
		String a,b,c;
        
		BufferedReader x= new BufferedReader(new InputStreamReader(System.in));
                a=x.readLine();
		b=x.readLine();
		c=x.readLine();
		a1=Integer.parseInt(a);
		b1=Integer.parseInt(b);
		c1=Integer.parseInt(c);
		if (a*a + b*b == c*c)
		System.out.print("To jest trojkat prostokatny");
		else
        System.out.print("To nie jest trojkat prostokatny");

    }
}

błąd

Main.java:17: error: bad operand types for binary operator '*'
		if (a*a + b*b = c*c)
		     ^
  first type:  String
  second type: String
Main.java:17: error: bad operand types for binary operator '*'
		if (a*a + b*b = c*c)
		           ^
  first type:  String
  second type: String
Main.java:17: error: bad operand types for binary operator '*'
		if (a*a + b*b = c*c)
		                 ^
  first type:  String
  second type: String
3 errors

dodanie znacznika <code> - Furious Programming

1

Zamiast:

if (a*a + b*b == c*c)

napisz:

if (a1*a1 + b1*b1 == c1*c1)
1

Trójkąt w którym

a1*a1 == b1*b1 + c1*c1

również jest prostokątny.

if ((a1*a1 + b1*b1 == c1*c1) || (a1*a1 + c1*c1 == b1*b1) || (c1*c1 + b1*b1 == a1*a1))

1 użytkowników online, w tym zalogowanych: 0, gości: 1