University stuff.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Beslutninger.java 784B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import java.util.Scanner;
  2. class Beslutninger {
  3. private static void a() {
  4. int age = 18;
  5. }
  6. private static void b() {
  7. int age = 18;
  8. //Checks the user's age, telling whether they're legal age or not
  9. if (age >= 18) {
  10. System.out.println("You're of legal age.");
  11. } else {
  12. System.out.println("You're not of legal age.");
  13. }
  14. }
  15. private static void c() {
  16. Scanner s = new Scanner(System.in);
  17. //Asks the user how old they are
  18. System.out.println("How old are you?");
  19. int age = s.nextInt();
  20. //Checks the user's age, telling whether they're legal age or not
  21. if (age >= 18) {
  22. System.out.println("You're of legal age.");
  23. } else {
  24. System.out.println("You're not of legal age.");
  25. }
  26. }
  27. public static void main(String[] args) {
  28. a();
  29. b();
  30. c();
  31. }
  32. }