-
Notifications
You must be signed in to change notification settings - Fork 0
/
program1.java
43 lines (36 loc) · 1.66 KB
/
program1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Calculate {
public static void main(String[] args) {
int width = 0;
int length = 0;
int perimeter = 0;
try
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//recebe o comprimento do retangulo
System.out.println("Please enter length of a rectangle");
length = Integer.parseInt(br.readLine());
//recebe a largura do retangulo
System.out.println("Please enter width of a rectangle");
width = Integer.parseInt(br.readLine());
}
//trata a excecao de formato de numero nao correspondente ao esperado
catch(NumberFormatException ne)
{
System.out.println("Invalid value" + ne);
System.exit(0);
}
//trata a excecao de erro no formato da entrada
catch(IOException ioe)
{
System.out.println("IO Error :" + ioe);
System.exit(0);
}
//calcula o perimetro
perimeter=2*length + 2*width;
//mostra o valor para o usuario
System.out.println("Perimeter of a rectangle is " + perimeter);
}
}