-
-
Save FreeFly19/081bbfc7da7a7d0452a6f2b64cab4d76 to your computer and use it in GitHub Desktop.
Home work #2
This file contains 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
import java.util.Scanner; | |
public class Ex1 { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
System.out.print("Введіть додатне число = "); | |
int a = in.nextInt(); | |
if ( a % 2 == 0 ) System.out.println("even"); | |
else System.out.println("odd"); | |
} | |
} |
This file contains 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 Ex2 { | |
public static void main(String[] args) { | |
final int COUNT = 10; | |
for (int i = 0; i < COUNT; i++) { | |
System.out.println("I will adopt best practices"); | |
} | |
} | |
} |
This file contains 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 Ex3 { | |
public static void main(String[] args) { | |
int a = 10; | |
do { | |
if (a != 1) System.out.print(a + ", "); | |
else System.out.print(a); | |
--a; | |
}while (a > 0); | |
} | |
} |
This file contains 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 Ex4 { | |
public static void main(String[] args) { | |
System.out.print("{ "); | |
for (int i = 0; i <= 20; i++) { | |
if (i < 20) System.out.print(i + ", "); | |
else System.out.print(i + " }"); | |
} | |
} | |
} |
This file contains 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
import java.util.Scanner; | |
public class Ex5 { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
System.out.print("Ввадіть преше число: "); | |
int first = in.nextInt(); | |
System.out.print("Введіть друге число: "); | |
int second = in.nextInt(); | |
for (int i = 1; i <= second ; i++) { | |
if ( i % first == 0 ) System.out.println(i); | |
} | |
} | |
} |
This file contains 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 Ex6 { | |
public static void main(String[] args) { | |
int j = 0; | |
do { | |
for (int i = 1; i <= 9; i++) { | |
for (int k = 1; k <= 9; k++) { | |
System.out.println(i + "*" + k + "=" + (i*k)); | |
} | |
System.out.println(); | |
++j; | |
} | |
} while( j <= 9); | |
} | |
} |
This file contains 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
import java.util.Scanner; | |
public class Ex7 { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
System.out.print("Введіть додатне число = "); | |
int count = in.nextInt(); | |
int sum = 0; | |
for (int i = 1; i <= count; i++) { | |
sum = sum + i; | |
if (count > i) System.out.print(i + "+"); | |
else System.out.print(i); | |
} | |
System.out.print("=" + sum); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment