Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions it/academy/course/hw1/Hello.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package it.academy.course.hw1;

import java.util.Scanner;

public class Hello {
public static void main(String[] args) {
hw1();
hw2(args);
hw3(args);
hw4(args);
hw5(args);
}

public static void hw1() {
System.out.println("Task-1");
byte b = 0x55;
short s = 0x55ff;
int i = 1000000;
long l = 0xffffffffL;
char q = 'a';
float f = .25f;
double d = .00001234;
boolean bool = true;
System.out.printf("b = %d\ns = %d\ni = %d\nl = %d\nq = %c\nf = %2f\nd = %8f\nbool = %s\n", b, s, i, l, q, f, d, bool);
}

public static void hw2(String[] args) {
System.out.println("\nTask-2");
Scanner in = new Scanner(System.in);
System.out.println("Input first integer number");
int FirstInteger = in.nextInt();
System.out.println("Input second integer number");
int SecondInteger = in.nextInt();
System.out.println(resulthw2(FirstInteger, SecondInteger));
}
static int resulthw2(int x, int y){
return (x + y) + (x * y);
}

public static void hw3(String[] args){
System.out.println("\nTask-3");
Scanner in = new Scanner(System.in);
System.out.println("Please enter a period of time in seconds");
int FullSec = in.nextInt();
int weeks = FullSec / 604800;
int days = FullSec / 86400 % 7;
int hours = FullSec/ 3600 % 24;
int minutes = FullSec/ 60 % 60;
int seconds = FullSec % 60;
System.out.printf("weeks = %s\ndays = %s\nhours = %s\nminutes = %s\nseconds = %s\n", weeks, days, hours, minutes, seconds);
}
public static void hw4(String[] args) {
System.out.println("\nTask-4");
byte b = 12;
ByteConvert(b);

short s = 121;
ShortConvert(s);

int i = 1212;
IntConvert(i);

long l = 121212L;
LongConvert(l);

float f = 1.21f;
FloatConvert(f);

double d = 1.2121;

char c = 'a';
CharConvert(c);
}

static byte ByteConvert(byte x){
short q = (short) x;
System.out.println("byte to short = " + q);
int w = (int) x;
System.out.println("byte to int = " + w);
long e = (long) x;
System.out.println("byte to long = " + e);
return x;
}
static short ShortConvert(short x){
int q = (int) x;
System.out.println("short to int = " + q);
long w = (long) x;
System.out.println("short to long = " + w);
float e = (float) x;
System.out.println("short to float = " + e);
double r = (double) x;
System.out.println("short to double = " + r);
return x;
}
static int IntConvert(int x){
long q = (long) x;
System.out.println("int to long = " + q);
float w = (float) x;
System.out.println("int to float = " + w);
double e = (double) x;
System.out.println("int to double = " + e);
return x;
}
static long LongConvert(long x){
float q = (float) x;
System.out.println("long to float = " + q);
double w = (double) x;
System.out.println("long to double = " + w);
return x;
}
static char CharConvert(char x){
int q = (int) x;
System.out.println("char to int = " + q);
return x;
}
static float FloatConvert(float x){
double q = (double) x;
System.out.println("float to double = " + q);
return x;
}

public static void hw5(String[] args){
System.out.println("\nTask-5");
Scanner in = new Scanner(System.in);
System.out.println("Please enter any number");
int ReNumber = in.nextInt();
if (ReNumber > 0 && ReNumber % 2 == 0) {
System.out.println("0");
} else if (ReNumber > 0 && ReNumber % 2 != 0) {
System.out.println(ReNumber%2);
}
else {
System.out.println("Number is 0 or less than 0");
}

}
}
16 changes: 16 additions & 0 deletions it/academy/course/hw1/HomeTask_1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package it.academy.course.hw1;

public class HomeTask_1 {
public static void main(String[] args) {
System.out.println("Task-1");
byte b = 0x55;
short s = 0x55ff;
int i = 1000000;
long l = 0xffffffffL;
char q = 'a';
float f = .25f;
double d = .00001234;
boolean bool = true;
System.out.printf("b = %d\ns = %d\ni = %d\nl = %d\nq = %c\nf = %2f\nd = %8f\nbool = %s\n", b, s, i, l, q, f, d, bool);
}
}
18 changes: 18 additions & 0 deletions it/academy/course/hw1/HomeTask_2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package it.academy.course.hw1;

import java.util.Scanner;

public class HomeTask_2 {
public static void main(String[] args) {
System.out.println("\nTask-2");
Scanner in = new Scanner(System.in);
System.out.println("Input first integer number");
int FirstInteger = in.nextInt();
System.out.println("Input second integer number");
int SecondInteger = in.nextInt();
System.out.println(resulthw2(FirstInteger, SecondInteger));
}
static int resulthw2(int x, int y){
return (x + y) + (x * y);
}
}
18 changes: 18 additions & 0 deletions it/academy/course/hw1/HomeTask_3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package it.academy.course.hw1;

import java.util.Scanner;

public class HomeTask_3 {
public static void main(String[] args) {
System.out.println("\nTask-3");
Scanner in = new Scanner(System.in);
System.out.println("Please enter a period of time in seconds");
int FullSec = in.nextInt();
int weeks = FullSec / 604800;
int days = FullSec / 86400 % 7;
int hours = FullSec/ 3600 % 24;
int minutes = FullSec/ 60 % 60;
int seconds = FullSec % 60;
System.out.printf("weeks = %s\ndays = %s\nhours = %s\nminutes = %s\nseconds = %s\n", weeks, days, hours, minutes, seconds);
}
}
89 changes: 89 additions & 0 deletions it/academy/course/hw1/HomeTask_4.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package it.academy.course.hw1;



public class HomeTask_4 {
public static void main(String[] args) {
System.out.println("\nTask-4");
byte b = 12;
ByteConvert(b);

short s = 121;
ShortConvert(s);

int i = 1212;
IntConvert(i);

long l = 121212L;
LongConvert(l);

float f = 1.21f;
FloatConvert(f);

double d = 1.2121;

char c = 'a';
CharConvert(c);
}

static byte ByteConvert(byte x){
short q = (short) x;
System.out.println("byte to short = " + q);
int w = (int) x;
System.out.println("byte to int = " + w);
long e = (long) x;
System.out.println("byte to long = " + e);
return x;
}
static short ShortConvert(short x){
int q = (int) x;
System.out.println("short to int = " + q);
long w = (long) x;
System.out.println("short to long = " + w);
float e = (float) x;
System.out.println("short to float = " + e);
double r = (double) x;
System.out.println("short to double = " + r);
byte t = (byte) x;
System.out.println("short to byte = " + t);
return x;
}
static int IntConvert(int x){
long q = (long) x;
System.out.println("int to long = " + q);
float w = (float) x;
System.out.println("int to float = " + w);
double e = (double) x;
System.out.println("int to double = " + e);
byte r = (byte) x;
System.out.println("int to byte = " + r);
short t = (short) x;
System.out.println("int to short = " + t);
char y = (char) x;
System.out.println("int to char = " + y);
return x;
}
static long LongConvert(long x){
float q = (float) x;
System.out.println("long to float = " + q);
double w = (double) x;
System.out.println("long to double = " + w);
byte e = (byte) x;
System.out.println("long to short = " + e);
short r = (short) x;
System.out.println("long to short = " + r);
int t = (int) x;
System.out.println("long to int = " + t);
return x;
}
static char CharConvert(char x){
int q = (int) x;
System.out.println("char to int = " + q);
return x;
}
static float FloatConvert(float x){
double q = (double) x;
System.out.println("float to double = " + q);
return x;
}
}
19 changes: 19 additions & 0 deletions it/academy/course/hw1/HomeTask_5.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package it.academy.course.hw1;

import java.util.Scanner;

public class HomeTask_5 {
public static void main(String[] args) {
System.out.println("\nTask-5");
Scanner in = new Scanner(System.in);
System.out.println("Please enter any number");
int ReNumber = in.nextInt();
if (ReNumber > 0 && ReNumber % 2 == 0) {
System.out.println("0");
} else if (ReNumber > 0 && ReNumber % 2 != 0) {
System.out.println(ReNumber % 2);
} else {
System.out.println("Number is 0 or less than 0");
}
}
}
9 changes: 9 additions & 0 deletions it/academy/course/hw1/JavaForJunior.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package it.academy.course.hw1;

import javax.swing.*;

public class JavaForJunior {
public static void main(String[] args) {
JOptionPane.showMessageDialog(null, "First program on java");
}
}
22 changes: 22 additions & 0 deletions it/academy/course/hw10/task1/Home10Task_1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package it.academy.course.hw10.task1;

import java.util.*;

public class Home10Task_1 {

public static void main(String[] args) {
Set<Integer> set1 = new HashSet<>();
Collections.addAll(set1, 2, 4, 14, 12, 5, 22, 55);
SetOperations.printSet("set1", set1);
Set<Integer> set2 = new LinkedHashSet<>();
Collections.addAll(set2, 1, 4, 12, 15, 55, 11, 21, 29);
SetOperations.printSet("set2", set2);
Set<Integer> set3 = new TreeSet<>();
Collections.addAll(set3, 2, 5, 40, 82, 41, 13, 12, 21);
SetOperations.printSet("set3", set3);
Set<?> set4 = SetOperations.intersect(set1, set2);
SetOperations.printSet("set1 intersect set2", set4);
SetOperations.printSet("set1 intersect set2 union set3", SetOperations.union(set4, set3));

}
}
22 changes: 22 additions & 0 deletions it/academy/course/hw10/task1/SetOperations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package it.academy.course.hw10.task1;

import java.util.HashSet;
import java.util.Set;

public class SetOperations {
public static Set<?> union(Set<?> set1, Set<?> set2) {
Set<Object> resultUnion = new HashSet<>(set1);
resultUnion.addAll(set2);
return resultUnion;
}

public static Set<?> intersect(Set<?> set1, Set<?> set2) {
Set<?> resultIntersect = new HashSet<>(set1);
resultIntersect.retainAll(set2);
return resultIntersect;
}

public static void printSet(String name, Set set) {
System.out.printf("%s: %s\n", name, set);
}
}
28 changes: 28 additions & 0 deletions it/academy/course/hw10/task2/Home10Task_2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package it.academy.course.hw10.task2;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Home10Task_2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter text");
String text = in.nextLine();
Map<String, Integer> wordCount = new HashMap<>();
String[] words = text.split("\\s+");
for (String word : words) {
word = word.replaceAll("[^a-zA-Zа-яА-Я]", "");
if (word.length() > 0) {
if (wordCount.containsKey(word)) {
wordCount.put(word, wordCount.get(word) + 1);
} else {
wordCount.put(word, 1);
}
}
}
for (Map.Entry<String, Integer> entry : wordCount.entrySet()) {
System.out.println(entry.getKey() + " - " + entry.getValue());
}
}
}
Loading