Open Andy179176 opened 2 years ago
ДЗ №1 public class Main {
public static void main(String[] args) {
String word1 = "hello";
String word2 = "hello";
System.out.println("1. Method: "+checkWord(word1,word2));
System.out.println("2. Method: "+checkWord2(word1,word2));
}
public static boolean checkWord (String word1, String word2){
return word1 == "hello" || word2 == "hello";
// если ХОТЯ БЫ один из двух аргументов равен "hello"
}
public static boolean checkWord2 (String word1, String word2){
return word1 == "hello" ^ word2 == "hello";
// если ТОЛЬКО один из двух аргументов равен "hello"
}
ДЗ №2 public class Main {
public static void main(String[] args) {
int a=6;
int b=3;
System.out.println("Число "+a+" делится на число "+b+" без остатка: "+checkDiv(a,b));
}
public static boolean checkDiv(int a, int b){
return a % b == 0;
}
}
ДЗ №3 public class Main {
public static void main(String[] args) {
int month = 7;
System.out.println(month+" - это номер месяца: "+checkMonth(month));
}
public static boolean checkMonth (int month){
return month >=1 && month <=12;
}
}
ДЗ №4 public class Main {
public static void main(String[] args) {
int time = 23;
String door = "открыта";
System.out.println("Alarm: "+checkAlarmController(time, door));
}
public static boolean checkAlarmController (int time, String door){
return ((time >=22 && time <=24) || (time >=0 && time <=7)) && door=="открыта";
}
}
1) Implement the method that returns true if one of its two arguments is equal “hello” 2) Implement the method boolean checkDiv(int a, int b) that checks if [int a] is divisible by [int b] without any remainder or not. (Hint: There is the modulo (%) operator in Java. The % operator that returns the remainder of two integers. For example 17%3 is 2 because 17 divided by 3 leaves a remainder of 2, but 15%3 is 0). Print the result in the main method. Examples: checkDiv (10,2) -> true checkDiv (10,3) -> false 3) Write the method boolean checkMonth(int month) that takes an integer and returns true, if this int can be interpreted as month number, else returns false. Print the result in the main method. Examples: checkMonth(10) -> true, checkMonth(15) -> false. 4) * Implement an alarm controller method. It should alarm (return true) if the door is open and the time is between 22 pm and 7am. It should return false otherwise.