Skip to content

Instantly share code, notes, and snippets.

@FreeFly19
Last active October 23, 2016 22:06
Show Gist options
  • Save FreeFly19/081bbfc7da7a7d0452a6f2b64cab4d76 to your computer and use it in GitHub Desktop.
Save FreeFly19/081bbfc7da7a7d0452a6f2b64cab4d76 to your computer and use it in GitHub Desktop.
Home work #2
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");
}
}
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");
}
}
}
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);
}
}
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 + " }");
}
}
}
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);
}
}
}
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);
}
}
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