Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.print("Podaj odległość w metrach: ");
- double meters = input.nextDouble();
- if(meters < 0)
- {
- System.out.println("BLAD");
- System.exit(0);
- }
- do
- {
- menu();
- int choice = input.nextInt();
- switch (choice)
- {
- case 1:
- showKilometres(meters);
- break;
- case 2:
- showInches(meters);
- break;
- case 3:
- showFeet(meters);
- break;
- case 4:
- System.exit(0);
- break;
- default:
- System.out.println("BLAD");
- }
- } while (true);
- }
- public static void showKilometres(double meters)
- {
- System.out.println("Kilometry = " + (meters * 0.001));
- }
- public static void showInches(double meters)
- {
- System.out.println("Cale = " + (meters * 39.37));
- }
- public static void showFeet(double meters)
- {
- System.out.println("Stopy = " + (meters * 3.281));
- }
- public static void menu()
- {
- System.out.println("1. Przelicz na kilometry");
- System.out.println("2. Przelicz na cale");
- System.out.println("3. Przelicz na stopy");
- System.out.println("4. Zamknij program");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment