-
-
Save FreeFly19/15529b429a05516eb2693d8fbf74d340 to your computer and use it in GitHub Desktop.
Home work#2 Заїка Олександр
This file contains hidden or 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
| package com.company; | |
| import java.util.Scanner; | |
| public class Main { | |
| public static void main(String[] args) { | |
| Scanner sc = new Scanner(System.in); | |
| System.out.print("Введіть число:"); | |
| int a = sc.nextInt(); | |
| if (a > 0) { | |
| if (a % 2 == 0) { | |
| System.out.println("even"); | |
| } else { | |
| System.out.println("odd"); | |
| } | |
| } else { | |
| System.out.println("Число відємне"); | |
| } | |
| } | |
| } |
This file contains hidden or 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 While { | |
| public static void main(String[] args) { | |
| Scanner sc = new Scanner(System.in); | |
| int a = sc.nextInt(); | |
| int i = 0; | |
| while( i < a ) { | |
| System.out.println("I will adopt best practices"); | |
| i++; | |
| } | |
| } | |
| } |
This file contains hidden or 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
| package com.company; | |
| public class Chusla { | |
| public static void main(String[] args) { | |
| for (int i = 10;i >= 0; i--) { | |
| System.out.print(i + ", "); | |
| } | |
| } | |
| } |
This file contains hidden or 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
| package com.company; | |
| public class Parni { | |
| public static void main(String[] args) { | |
| for (int i = 0; i <= 20; i+=2) { | |
| System.out.println(i); | |
| } | |
| } | |
| } |
This file contains hidden or 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 Zminnni { | |
| public static void main(String[] args) { | |
| Scanner sc = new Scanner(System.in); | |
| System.out.print("Введіть змінну m = "); | |
| int m = sc.nextInt(); | |
| System.out.print("Введіть змінну n = "); | |
| int n = sc.nextInt(); | |
| for (int i = 1; i <= n; i++) { | |
| if (i % m != 0) continue; | |
| System.out.println(i); | |
| } | |
| } | |
| } |
This file contains hidden or 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
| package com.company; | |
| import java.util.Scanner; | |
| public class Tabl { | |
| public static void main(String[] args) { | |
| Scanner sc = new Scanner(System.in); | |
| System.out.print("Введіть число, для якого потрібно відобразити таблицю множення:"); | |
| int a = sc.nextInt(); | |
| int i = 0; | |
| while (i <= 10) { | |
| int b = a * i; | |
| System.out.println(a + "*" + i + "=" + b); | |
| i++; | |
| } | |
| } | |
| } |
This file contains hidden or 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
| package com.company; | |
| import java.util.Scanner; | |
| public class Arufm { | |
| public static void main(String[] args) { | |
| Scanner sc = new Scanner(System.in); | |
| System.out.print("Введіть останнє число арифметичної прогресії: "); | |
| int n = sc.nextInt(); | |
| int sum = 0; | |
| for (int i = 1; i <= n; i++) { | |
| sum += i; | |
| } | |
| System.out.println("Сума арифметичної прогресії: " + sum); | |
| } | |
| } |
This file contains hidden or 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
| package com.company; | |
| public class Tablzslesh { | |
| public static void main(String[] args) { | |
| for(int a = 1; a < 10; a++) { | |
| int i = 1; | |
| while (i < 10) { | |
| int c = a * i; | |
| if (a == i) | |
| System.out.print(" #|"); | |
| else | |
| System.out.printf("%3s", c + "|"); | |
| i++; | |
| } | |
| System.out.println(" Табличка множення на:" + a); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment