Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.InputMismatchException;
- public class Program_2_1 {
- public static void main () {
- System.out.println("Zadanie 2.1 \n");
- boolean run = true;
- while (run) {
- try{
- Scanner in = new Scanner(System.in);
- System.out.println("Oblicz pole prostokąta");
- System.out.println("Podaj długość boku a \n");
- int a = in.nextInt();
- System.out.println("Podaj długość boku b \n");
- int b = in.nextInt();
- if (a<=0 || b<=0) {
- System.out.println("Długość boku nie może być mniejsza bądź równa 0 \n");
- } else {
- System.out.println("Pole prostokąta wynosi: " +a*b+ "\n");
- }
- System.out.println("Oblicz obwód prostokąta");
- System.out.println("Podaj długość boku a \n");
- int c = in.nextInt();
- System.out.println("Podaj długość boku b \n");
- int d = in.nextInt();
- int obwod = 2*c + 2*d;
- if (c<=0 || d<=0) {
- System.out.println("Długość boku nie może być mniejsza bądź równa 0 \n");
- } else {
- System.out.println("Obwód prostokąta wynosi: " +obwod+ "\n");
- }
- }
- catch (InputMismatchException e){
- System.out.println("Niewłaściwe dane, podaj cyfrę \n");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement