Skip to content

Instantly share code, notes, and snippets.

@FreeFly19
Forked from OlexsandrZ/Ex1
Last active October 24, 2016 14:44
Show Gist options
  • Save FreeFly19/15529b429a05516eb2693d8fbf74d340 to your computer and use it in GitHub Desktop.
Save FreeFly19/15529b429a05516eb2693d8fbf74d340 to your computer and use it in GitHub Desktop.
Home work#2 Заїка Олександр
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("Число відємне");
}
}
}
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++;
}
}
}
package com.company;
public class Chusla {
public static void main(String[] args) {
for (int i = 10;i >= 0; i--) {
System.out.print(i + ", ");
}
}
}
package com.company;
public class Parni {
public static void main(String[] args) {
for (int i = 0; i <= 20; i+=2) {
System.out.println(i);
}
}
}
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);
}
}
}
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++;
}
}
}
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);
}
}
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