Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 73 additions & 1 deletion src/homework/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,80 @@
package homework;

import javax.sql.rowset.serial.SQLOutputImpl;

public class Main {

public static void main(String[] args) {
// write your code here
detectAndPrintNumberSign(-5);
detectAndPrintNumberSign(0);
detectAndPrintNumberSign(7);
boolean res = checkNumberSign(6);
printStringNumberOfTimes("Hello", 5);
System.out.println(year(400));
System.out.println(year(800));
System.out.println(year(1200));
System.out.println(year(1201));
System.out.println(year(100));
System.out.println(year(200));
System.out.println(year(300));
System.out.println(year(104));
System.out.println(year(3));
System.out.println(year(4));
System.out.println(year(7));
System.out.println(year(8));
}

public static boolean checkSum(int a, int b) {

int s = a + b;
if ((s >= 10) && (s <= 20)) {
return true;
} else {
return false;
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

можно без ветвления.
просто return (s >= 10) && (s <= 20)


public static void detectAndPrintNumberSign(int number) {
if (number < 0) {
System.out.println("Отрицательное: " + number);
} else {
System.out.println("Положительное: " + number);
}

}

public static boolean checkNumberSign(int a) {

if (a < 0) {
return true;
} else {
return false;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return a < 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут ветвления не нужны

}

public static void printStringNumberOfTimes(String str, int numberOfTimes) {

for (int i = 0; i < numberOfTimes; i++) {
System.out.println(str);
}


}

public static boolean year(int year) {
System.out.println();
System.out.println("year: " + year);
if (year % 100 == 0 && year % 400 != 0) {

return false;
} else if (year % 400 == 0) {
return true;
} else if (year % 4 == 0) {
return true;
} else {
return false;
}
}
}