-
-
Save FreeFly19/6cce0c7aec254609c097affbb772a456 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
/** | |
* 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"); | |
} | |
} | |
} |
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
/** | |
* 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"); | |
} | |
} | |
} |
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
/** | |
* 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+", "); | |
} | |
} | |
} |
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
/** | |
* 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 + " "); | |
} | |
} | |
} |
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; | |
/** | |
* 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+" "); | |
} | |
} | |
} | |
} |
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
/** | |
* 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(); | |
} | |
} | |
} |
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; | |
/** | |
* 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); | |
} | |
} |
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
/** | |
* 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