Created
August 23, 2024 18:56
-
-
Save alibehzadian/9fb8fbdae99d80d7a06634d0f3c73955 to your computer and use it in GitHub Desktop.
Examples of Episode 9 of Java Complete Course in Farsi/Persian
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
System.out.println("Enter an integer:"); | |
int number = in.nextInt(); | |
boolean isEvenNumber = number % 2 == 0; | |
if(isEvenNumber) { | |
System.out.printf("The number %d is even!", number); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
System.out.println("Enter an integer:"); | |
int number = in.nextInt(); | |
boolean isEvenNumber = number % 2 == 0; | |
if(isEvenNumber) { | |
System.out.printf("The number %d is even!", number); | |
} else { | |
System.out.printf("The number %d is odd!", number); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
System.out.print("Enter Day-of-Week: "); | |
int dayOfWeek = in.nextInt(); | |
if (dayOfWeek == 1) { | |
System.out.println("Monday"); | |
} else if (dayOfWeek == 2) { | |
System.out.println("Tuesday"); | |
} else if (dayOfWeek == 3) { | |
System.out.println("Wednesday"); | |
} else if (dayOfWeek == 4) { | |
System.out.println("Thursday"); | |
} else if (dayOfWeek == 5) { | |
System.out.println("Friday"); | |
} else if (dayOfWeek == 6) { | |
System.out.println("Saturday"); | |
} else if (dayOfWeek == 7) { | |
System.out.println("Sunday"); | |
} else { | |
System.out.println("Invalid day of week!"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
System.out.print("Enter Day-of-Week: "); | |
int dayOfWeek = in.nextInt(); | |
switch (dayOfWeek) { | |
case 1: | |
System.out.println("Monday"); | |
break; | |
case 2: | |
System.out.println("Tuesday"); | |
break; | |
case 3: | |
System.out.println("Wednesday"); | |
break; | |
case 4: | |
System.out.println("Thursday"); | |
break; | |
case 5: | |
System.out.println("Friday"); | |
break; | |
case 6: | |
System.out.println("Saturday"); | |
break; | |
case 7: | |
System.out.println("Sunday"); | |
break; | |
default: | |
System.out.println("Invalid day of week!"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
int dayOfWeek = 3; | |
String dayOfWeekName = switch(dayOfWeek) { | |
case 1 -> "Monday"; | |
case 2 -> "Tuesday"; | |
case 3 -> "Wednesday"; | |
case 4 -> "Thursday"; | |
case 5 -> "Friday"; | |
case 6 -> "Saturday"; | |
case 7 -> "Sunday"; | |
default -> "Invalid day of week!"; | |
}; | |
System.out.println(dayOfWeekName); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
int dayOfWeek = 3; | |
String dayOfWeekName = switch (dayOfWeek) { | |
case 1 -> { | |
System.out.println("Monday"); | |
yield "Monday"; | |
} | |
case 2 -> { | |
System.out.println("Tuesday"); | |
yield "Tuesday"; | |
} | |
case 3 -> { | |
System.out.println("Wednesday"); | |
yield "Wednesday"; | |
} | |
case 4 -> { | |
System.out.println("Thursday"); | |
yield "Thursday"; | |
} | |
case 5 -> { | |
System.out.println("Friday"); | |
yield "Friday"; | |
} | |
case 6 -> { | |
System.out.println("Saturday"); | |
yield "Saturday"; | |
} | |
case 7 -> { | |
System.out.println("Sunday"); | |
yield "Sunday"; | |
} | |
default -> { | |
System.out.println("Invalid day of week!"); | |
yield "Invalid day of week!"; | |
} | |
}; | |
System.out.println("Day of week name after switch: " + dayOfWeekName); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
System.out.print("Enter Month of the year: "); | |
int monthOfYear = in.nextInt(); | |
switch (monthOfYear) { | |
case 1, 2, 3 -> System.out.println("Spring!"); | |
case 4, 5, 6 -> System.out.println("Summer!"); | |
case 7, 8, 9 -> System.out.println("Fall!"); | |
case 10, 11, 12 -> System.out.println("Winter!"); | |
default -> System.out.println("We only have 4 seasons!"); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
System.out.print("Enter Month of the year: "); | |
int monthOfYear = in.nextInt(); | |
switch (monthOfYear) { | |
case 1, 2, 3 -> { | |
System.out.println("Spring!"); | |
System.out.println("Spring is the season of reunions!"); | |
} | |
case 4, 5, 6 -> { | |
System.out.println("Summer!"); | |
System.out.println("Summer is the best season for trip!"); | |
} | |
case 7, 8, 9 -> { | |
System.out.println("Fall!"); | |
System.out.println("Fall is the lovers' season!"); | |
} | |
case 10, 11, 12 -> { | |
System.out.println("Winter!"); | |
System.out.println("Do you like skiing?"); | |
} | |
default -> System.out.println("We only have 4 seasons!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment