Skip to content

Instantly share code, notes, and snippets.

@FreeFly19
Last active October 23, 2016 21:45
Show Gist options
  • Save FreeFly19/6cce0c7aec254609c097affbb772a456 to your computer and use it in GitHub Desktop.
Save FreeFly19/6cce0c7aec254609c097affbb772a456 to your computer and use it in GitHub Desktop.
Home work #2 Чуєнко Віталій
/**
* Created by Чуєнко Віталій on 19.10.2016.
*/
public class Ex1 {
public static void main(String[] args) {
int a = 4;
if (a % 2 == 0) {
System.out.println("even");
} else {
System.out.println("odd");
}
}
}
/**
* Created by Чуєнко Віталій on 19.10.2016.
*/
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");
}
}
}
/**
* Created by Чуєнко Віталій on 19.10.2016.
*/
public class Ex3 {
public static void main(String[] args) {
for (int i = 10; i != 0; i--) {
System.out.print(i+", ");
}
}
}
/**
* Created by Чуєнко Віталій on 19.10.2016.
*/
public class Ex4 {
public static void main(String[] args) {
for (int i=0; i<=20; i+=2){
System.out.print(i + " ");
}
}
}
import java.util.Scanner;
/**
* Created by Чуєнко Віталій on 19.10.2016.
*/
public class Ex5 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Введіть m: ");
int m = scanner.nextInt();
System.out.print("введіть n: ");
int n = scanner.nextInt();
for (int i=1; i<=n; i++){
if (i % m == 0){
System.out.print(i+" ");
}
}
}
}
/**
* Created by Чуєнко Віталій on 19.10.2016.
*/
public class Ex6 {
public static void main(String[] args) {
for (int i=1; i<10; i++){
for (int j=1; j<10; j++){
System.out.print(i*j + "\t");
}
System.out.println();
}
}
}
import java.util.Scanner;
/**
* Created by Чуєнко Віталій on 19.10.2016.
*/
public class Ex7 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Введіть кількість елементів, для яких необхідно порахувати суму арифметичного ряду: ");
int n = in.nextInt();
int sum = 0;
for (int i=1; i<=n; i++){
sum += i;
}
System.out.println(sum);
}
}
/**
* Created by Чуєнко Віталій on 19.10.2016.
*/
public class Ex8 {
public static void main(String[] args) {
for (int i = 1; i < 10; i++) {
for (int j = 1; j < 10; j++) {
if (i < j) {
System.out.print("#\t");
} else {
System.out.print(i * j + "\t");
}
}
System.out.println();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment