Skip to content

Instantly share code, notes, and snippets.

View ElenaOhana's full-sized avatar
🏠
Working from home

Petina Elena ElenaOhana

🏠
Working from home
View GitHub Profile
@ElenaOhana
ElenaOhana / Reception.java
Created February 23, 2019 10:43
helloProj
public class Reception {
static void greet() {
//sout + Tab
System.out.println("Hello from greet");
manage();
}
static void manage() {
System.out.println("Manager smth");
@ElenaOhana
ElenaOhana / TernExample.java
Last active March 20, 2019 13:55
Ternar operetor & Pre increment
public class TernExample {
public static void main(String[] args) {
//Pre increment vs Post increment
int x;
int a;
a = 0;
x = 0;
a = x++;
System.out.println(a + " " + x); // a == 0, x == 1
a = 0;
@ElenaOhana
ElenaOhana / TestLineMethodMultT.java
Last active March 28, 2019 17:00
Multiplication table with testLine() method
public class TestLineMethodMultT {
public static void main(String[] args) {
testLine(2, 6);
testLine(6, 10);
}
private static void testLine(int a, int b) {
for (int i = 2; i < 10; i++) {
for (int j = a; j < b; j++) {
System.out.printf("%d * %d = %2d\t", j, i, i * j);
@ElenaOhana
ElenaOhana / Test3MultTable.java
Created March 28, 2019 16:55
тройной for
public class Test3MultTable {
public static void main(String[] args) {
//testLine(2, 6);
//testLine(6, 10);
//static void testLine ( int a, int b){
//исходя из его отработок рассчитать пары a и b
for (int a = 2; a <= 6; a += 4) {
for (int i = 2; i < 10; i++) {
for (int j = a; j < (a + 4); j++) {
@ElenaOhana
ElenaOhana / Test2MultTable.java
Created March 28, 2019 17:02
Талица умножения в 2 отдельных for
public class Test2MultTable {
public static void main(String[] args) {
// long n = 461012;
// System.out.format("%d%n", n); // --> "461012"
// System.out.format("%08d%n", n); // --> "00461012"
// System.out.format("%+8d%n", n); // --> " +461012"
// System.out.format("%,8d%n", n); // --> " 461,012"
// System.out.format("%+,8d%n%n", n); // --> "+461,012"
//
// double pi = Math.PI;
@ElenaOhana
ElenaOhana / Test3RPGGame1.java
Created March 29, 2019 10:08
Возвращение начений из метода
public class Test3RPGGame1 {
public static void main(String[] args) {
int hp = testRandom(50, 120);
int damage = testRandom(20, 150);
int shield = testRandom(0, 80);
System.out.printf("hp: %d, damage: %d, shield: %d%n", hp, damage, shield);
int resultDamage = damage - shield;
if (resultDamage > 0){
@ElenaOhana
ElenaOhana / Test4Receipt.java
Created March 29, 2019 11:03
Возвращение начений из метода (String)
public class Test4Receipt {
public static void main(String[] args) {
String plate;
plate = "листья салата, ";
plate = plate + "соль, ";
plate += "лимон, ";
plate += "черный перец, ";
plate = plate + blender("помидорки");
@ElenaOhana
ElenaOhana / BMIIndex.java
Last active March 30, 2019 16:51
With Scanner Class
import java.util.Scanner;
public class BMIIndex {
public static void main(String[] args) {
//double height;
//height = 166;
//double weight;
//weight = 60;
Scanner scanner = new Scanner(System.in);
import java.util.ArrayList;
public class TestArrayListExample1 {
public static void main(String[] args) {
newMenu();
System.out.println(newMenu());
}
public static ArrayList newMenu() {
ArrayList menu = new ArrayList();
@ElenaOhana
ElenaOhana / TwoArraysThreeNum.java
Last active April 13, 2019 12:36
To fill arrays: arr1[i] = k * (i - t); arr2[i] = (k + t - i);
import java.util.Arrays;
import java.util.Scanner;
public class TwoArraysThreeNum {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter first integer: ");
int k = sc.nextInt();
sc.nextLine();
System.out.print("Enter second integer: ");