Skip to content

Instantly share code, notes, and snippets.

@piotrplaneta
Created February 27, 2013 08:36
Show Gist options
  • Select an option

  • Save piotrplaneta/5046326 to your computer and use it in GitHub Desktop.

Select an option

Save piotrplaneta/5046326 to your computer and use it in GitHub Desktop.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package triangle;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
*
* @author Student
*/
public class Triangle {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line = reader.readLine();
int firstNumber = Integer.valueOf(line);
line = reader.readLine();
int secondNumber = Integer.valueOf(line);
line = reader.readLine();
int thirdNumber = Integer.valueOf(line);
if (checkTriangle(firstNumber, secondNumber, thirdNumber)) {
if(firstNumber == secondNumber && secondNumber == thirdNumber) {
System.out.println("równoboczny");
} else if(firstNumber == secondNumber ||
secondNumber == thirdNumber ||
firstNumber == thirdNumber) {
System.out.println("równoramienny");
} else {
System.out.println("Zwykły");
}
} else {
System.out.println("Nie trójkąt");
}
}
public static boolean checkTriangle(int a, int b, int c) {
if(a + b <= c || b + c <= a || a + c <= b) {
return false;
} else {
return true;
}
}
}
/* Test cases:
*
* 1 1 1 - równoboczny
* 0 0 0 - nie trójkąt
* 0 1 1 - nie trójkąt
* 1 0 1 - nie trójkąt
* 1 1 0 - nie trójkąt
* 1 1 7 - nie trójkąt
* 1000000000 100000000 100000000 - nie ma w zadaniu określone jak duże mogą być dane
* 4 4 5 - równoramienny
* 4 5 4 - równoramienny
* 5 4 4 - równoramienny
* 1 2 3 - nie trójkąt
* 4 5 6 - zwykły
* -2 4 3 - nie trójkąt
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment