Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 01. Student Information
- public class P01StudentInformation {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String name = scanner.nextLine();
- int age = Integer.parseInt(scanner.nextLine());
- double grade = Double.parseDouble(scanner.nextLine());
- System.out.printf("Name: %s, Age: %d, Grade: %.2f", name, age, grade);
- }
- }
- ==================================================================================
- 02. Passed
- public class P02Passed {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double grade = Double.parseDouble(scanner.nextLine());
- if (grade >= 3) {
- System.out.println("Passed!");
- }
- }
- }
- ==================================================================================
- 03. Passed or Failed
- public class P02Passed {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- double grade = Double.parseDouble(scanner.nextLine());
- if (grade >= 3) {
- System.out.println("Passed!");
- } else {
- System.out.println("Failed!");
- }
- }
- }
- ==================================================================================
- 04. Back In 30 Minutes
- public class P04BackIn30Minutes {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int initHour = Integer.parseInt(scanner.nextLine());
- int initMin = Integer.parseInt(scanner.nextLine());
- int allMinutes = (initHour * 60) + initMin + 30;
- int hour = allMinutes / 60;
- int min = allMinutes % 60;
- if (hour > 23) {
- hour = 0;
- }
- System.out.printf("%d:%02d", hour, min);
- }
- }
- ==================================================================================
- 05. Month Printer
- public class P05MonthPrinter {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int num = Integer.parseInt(scanner.nextLine());
- String month = "";
- switch (num) {
- case 1: month = "January";break;
- case 2: month = "February";break;
- case 3: month = "March";break;
- case 4: month = "April";break;
- case 5: month = "May";break;
- case 6: month = "June";break;
- case 7: month = "July";break;
- case 8: month = "August";break;
- case 9: month = "September";break;
- case 10: month = "October";break;
- case 11: month = "November";break;
- case 12: month = "December";break;
- default: month = "Error!";
- }
- System.out.println(month);
- }
- }
- ==================================================================================
- 06. Foreign Languages
- public class P06ForeignLanguages {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String country = scanner.nextLine();
- switch (country){
- case "England":
- case "USA":
- System.out.println("English");
- break;
- case "Spain":
- case "Argentina":
- case "Mexico":
- System.out.println("Spanish");
- break;
- default:
- System.out.println("unknown");
- }
- }
- }
- ==================================================================================
- 07. Theatre Promotion
- public class P07TheatrePromotion {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String day = scanner.nextLine();
- int age = Integer.parseInt(scanner.nextLine());
- boolean isNotValid = false;
- int price = 0;
- if (age >= 0 && age <= 18){
- if (day.equals("Weekday")) {
- price = 12;
- } else if (day.equals("Weekend")) {
- price = 15;
- } else if (day.equals("Holiday")) {
- price = 5;
- }
- } else if (age > 18 && age <= 64) {
- if (day.equals("Weekday")) {
- price = 18;
- } else if (day.equals("Weekend")) {
- price = 20;
- } else if (day.equals("Holiday")) {
- price = 12;
- }
- } else if (age > 64 && age <= 122) {
- if (day.equals("Weekday")) {
- price = 12;
- } else if (day.equals("Weekend")) {
- price = 15;
- } else if (day.equals("Holiday")) {
- price = 10;
- }
- } else {
- isNotValid = true;
- }
- if (isNotValid) {
- System.out.println("Error!");
- } else {
- System.out.printf("%d$", price);
- }
- }
- }
- ==================================================================================
- 08. Divisible by 3
- public class P08DivisibleBy3 {
- public static void main(String[] args) {
- for (int i = 3; i <= 100; i += 3) {
- System.out.println(i);
- }
- }
- }
- ==================================================================================
- 09. Sum of Odd Numbers
- public class P09SumOfOddNumbers {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int num = Integer.parseInt(scanner.nextLine());
- int sum = 0;
- for (int i = 1; i <= num * 2; i++) {
- if (i % 2 != 0) {
- System.out.println(i);
- sum = sum + i;
- }
- }
- System.out.printf("Sum: %d", sum);
- }
- }
- ==================================================================================
- 10. Multiplication Table
- public class P10MultiplicationTable {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int num = Integer.parseInt(scanner.nextLine());
- for (int i = 1; i <= 10; i++) {
- System.out.printf("%d X %d = %d%n", num, i, num * i);
- }
- }
- }
- ==================================================================================
- 11. Multiplication Table 2.0
- public class P11MultiplicationTable2 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int num = Integer.parseInt(scanner.nextLine());
- int times = Integer.parseInt(scanner.nextLine());
- if (times <= 10) {
- for (int i = times; i <= 10; i++) {
- System.out.printf("%d X %d = %d%n", num, i, num * i);
- }
- } else {
- System.out.printf("%d X %d = %d%n", num, times, num * times);
- }
- }
- }
- ==================================================================================
- 12. Even Number
- public class P12EvenNumber {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int num = Integer.parseInt(scanner.nextLine());
- while (num % 2 != 0) {
- System.out.println("Please write an even number.");
- num = Integer.parseInt(scanner.nextLine());
- // if (num % 2 == 0) {
- // System.out.printf("The number is: %d", Math.abs(num));
- // break;
- // } else {
- // System.out.println("Please write an even number.");
- // num = Integer.parseInt(scanner.nextLine());
- // }
- }
- System.out.printf("The number is: %d", Math.abs(num));
- }
- }
- ==================================================================================
- 13. Refactor Sum of Odd Numbers
- public class P13RefactorSumOfOddNumbers {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- int sum = 0;
- for (int i = 0; i < n; i++) {
- System.out.println(2 * i + 1);
- sum += 2 * i + 1;
- }
- System.out.printf("Sum: %d%n", sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement