14 |
15 |
16 |
--------------------------------------------------------------------------------
/06. Objects and Classes - Lab/SumBigNumbers_02.java:
--------------------------------------------------------------------------------
1 | import java.math.BigInteger;
2 | import java.util.Scanner;
3 |
4 | public class SumBigNumbers_02 {
5 | public static void main(String[] args) {
6 | Scanner scanner = new Scanner(System.in);
7 | BigInteger firstNumber = new BigInteger(scanner.nextLine());
8 | BigInteger secondNumber = new BigInteger(scanner.nextLine());
9 |
10 | System.out.println(firstNumber.add(secondNumber));
11 |
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/04. Methods - Exercise/MethodsRecap.java:
--------------------------------------------------------------------------------
1 | public class MethodsRecap {
2 |
3 | public static void main(String[] args) {
4 |
5 | String name = getName();
6 |
7 | int minNumber = getMinNumber(5, 10);
8 |
9 | System.out.println(minNumber);
10 | }
11 |
12 | public static String getName() {
13 |
14 | return "Desi";
15 | }
16 |
17 | public static int getMinNumber(int num1, int num2) {
18 |
19 | return Math.min(num1, num2);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/06. Objects and Classes - Lab/demo/Demo.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | import demo.Car;
4 |
5 | public class Demo {
6 | public static void main(String[] args) {
7 | //автокъща
8 |
9 | Car.print(); //staticß
10 | Car car1 = new Car(230,"Skoda", "blue");
11 | car1.setHp(450);
12 |
13 |
14 |
15 |
16 | }
17 | public static void printCar (Car car) {
18 | System.out.println(car.getHp());
19 | System.out.println(car.getBrand());
20 | }
21 | }
--------------------------------------------------------------------------------
/02. Data Types and Variables - Exercise/Elevator_03.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class Elevator_03 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int peopleCount = Integer.parseInt(scanner.nextLine());
10 | int capacity = Integer.parseInt(scanner.nextLine());
11 |
12 | double courses = Math.ceil(peopleCount * 1.0 / capacity);
13 |
14 | System.out.printf("%.0f", courses);
15 | }
16 | }
--------------------------------------------------------------------------------
/01. Basic Syntax, Conditional Statements and Loops - Lab/PassedOrFailed_03.java:
--------------------------------------------------------------------------------
1 | package BasicsOverview;
2 |
3 | import java.util.Scanner;
4 |
5 | public class PassedOrFailed_03 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | double grade = Double.parseDouble(scanner.nextLine());
10 | if (grade > 2.99) {
11 | System.out.println("Passed!");
12 | } else {
13 | System.out.println("Failed!");
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/06. Objects and Classes - Exercise/opinion_poll_03/Person.java:
--------------------------------------------------------------------------------
1 | package opinion_poll_03;
2 |
3 | public class Person {
4 |
5 | // 1. Fields
6 | private String name;
7 | private int age;
8 |
9 | // 2. Constructor
10 | public Person(String name, int age) {
11 | this.name = name;
12 | this.age = age;
13 | }
14 |
15 | // 3. Methods
16 | public String getName() {
17 | return this.name;
18 | }
19 |
20 | public int getAge() {
21 | return this.age;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/02. Data Types and Varibles - Lab/ReversedChars_07.java:
--------------------------------------------------------------------------------
1 | package DataTypes;
2 |
3 | import java.util.Scanner;
4 |
5 | public class ReversedChars_07 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | char firstSymbol = scanner.nextLine().charAt(0);
10 | char secondSymbol = scanner.nextLine().charAt(0);
11 | char thirdSymbol = scanner.nextLine().charAt(0);
12 |
13 | System.out.printf("%c %c %c", thirdSymbol, secondSymbol, firstSymbol);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/02. Data Types and Varibles - Lab/TownInfo_04.java:
--------------------------------------------------------------------------------
1 | package DataTypesAndVariables;
2 |
3 | import java.util.Scanner;
4 |
5 | public class TownInfo_04 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 | String town = scanner.nextLine();
9 | long population = Long.parseLong(scanner.nextLine());
10 | short area = Short.parseShort(scanner.nextLine());
11 |
12 | System.out.printf("Town %s has population of %d and area %d square km.", town, population, area);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/02. Data Types and Variables - Exercise/SumOfChars_04.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class SumOfChars_04 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int n = Integer.parseInt(scanner.nextLine());
10 | int sum = 0;
11 |
12 | for (int i = 1; i <= n; i++) {
13 |
14 | char symbol = scanner.nextLine().charAt(0);
15 | sum += (int) symbol;
16 | }
17 |
18 | System.out.println("The sum equals: " + sum);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/03. Arrays - Lab/ReverseAnArrayOfStrings_04.java:
--------------------------------------------------------------------------------
1 | package Arrays;
2 |
3 | import java.util.Scanner;
4 |
5 | public class ReverseAnArrayOfStrings_04 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 | String [] texts = scanner.nextLine().split(" ");
9 | //"a b c d e".split(" ") -> ["a", "b", "c", "d", "e"]
10 |
11 | for (int position = texts.length - 1; position >= 0; position--) {
12 | System.out.print(texts[position] + " ");
13 | }
14 |
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/06. Objects and Classes - Lab/BigFactorial_03.java:
--------------------------------------------------------------------------------
1 | import java.math.BigInteger;
2 | import java.util.Scanner;
3 |
4 | public class BigFactorial_03 {
5 | public static void main(String[] args) {
6 | Scanner scanner = new Scanner(System.in);
7 | int n = Integer.parseInt(scanner.nextLine());
8 | BigInteger factorial = new BigInteger("1");
9 | for (int number = 1; number <= n; number++) {
10 | factorial = factorial.multiply(BigInteger.valueOf(number));
11 | }
12 | System.out.print(factorial);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/01. Basic Syntax, Conditional Statements and Loops - Lab/RefactorSumOddNumbers_12.java:
--------------------------------------------------------------------------------
1 | package BasicsOverview;
2 |
3 | import java.util.Scanner;
4 |
5 | public class RefactorSumOddNumbers_12 {
6 | public static void main(String[] args) {
7 | Scanner sc = new Scanner(System.in);
8 | int n = Integer.parseInt(sc.nextLine());
9 | int sum = 0;
10 | for (int i = 0; i < n; i++) {
11 | System.out.println(2 * i + 1);
12 | sum += 2 * i + 1;
13 | }
14 | System.out.printf("Sum: %d%n", sum);
15 |
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/04. Methods - Lab/MathPower_08.java:
--------------------------------------------------------------------------------
1 | package Methods;
2 |
3 | import java.util.Scanner;
4 |
5 | public class MathPower_08 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 | int number = Integer.parseInt(scanner.nextLine());
9 | int power = Integer.parseInt(scanner.nextLine());
10 |
11 | System.out.printf("%.0f",calculatePower(number, power));
12 | }
13 |
14 | private static double calculatePower(int number, int power) {
15 | return Math.pow(number, power);
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/06. Objects and Classes - Exercise/advertisement_message_01/Main.java:
--------------------------------------------------------------------------------
1 | package advertisement_message_01;
2 |
3 | import java.util.Scanner;
4 |
5 | public class Main {
6 |
7 | public static void main(String[] args) {
8 |
9 | Scanner scanner = new Scanner(System.in);
10 |
11 | int n = Integer.parseInt(scanner.nextLine());
12 |
13 | Message message = new Message();
14 |
15 | for (int i = 0; i < n; i++) {
16 | String randomMessage = message.randomMessage();
17 | System.out.println(randomMessage);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/01. Basic Syntax, Conditional Statements and Loops - Exercise/TriangleOfNumbers_08.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class TriangleOfNumbers_08 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int n = Integer.parseInt(scanner.nextLine());
10 |
11 | for (int row = 1; row <= n; row++) {
12 |
13 | for (int number = 1; number <= row; number++) {
14 | System.out.print(row + " ");
15 | }
16 | System.out.println();
17 | }
18 |
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/06. Objects and Classes - Exercise/demo/Book.java:
--------------------------------------------------------------------------------
1 | package demo;
2 |
3 | public class Book {
4 |
5 | // 1. Fields
6 | private String title;
7 | private String author;
8 | private double price;
9 |
10 | // 2. Constructor
11 | public Book(String title, String author, double price) {
12 | this.title = title;
13 | this.author = author;
14 | this.price = price;
15 | }
16 |
17 | // 3. Methods
18 | public void sell() {
19 | System.out.printf("Book with title: %s was successfully sold for %.2f.", this.title, this.price);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/04. Methods - Exercise/Matrix_07.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class Matrix_07 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int n = Integer.parseInt(scanner.nextLine());
10 |
11 | printTable(n);
12 | }
13 |
14 | public static void printTable(int n) {
15 |
16 | for (int row = 1; row <= n; row++) {
17 | for (int col = 1; col <= n; col++) {
18 | System.out.print(n + " ");
19 | }
20 | System.out.println();
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/02. Data Types and Varibles - Lab/ConcatNames_05.java:
--------------------------------------------------------------------------------
1 | package DataTypes;
2 |
3 | import java.util.Scanner;
4 |
5 | public class ConcatNames_05 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 | String firstName = scanner.nextLine();
9 | String secondName = scanner.nextLine();
10 | String delimiter = scanner.nextLine();
11 |
12 | //начин 1
13 | //System.out.println(firstName + delimiter + secondName);
14 |
15 | //начин 2
16 | System.out.printf("%s%s%s", firstName, delimiter, secondName);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/03. Arrays - Exercise/CommonElements_02.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class CommonElements_02 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | String[] firstArray = scanner.nextLine().split(" ");
10 | String[] secondArray = scanner.nextLine().split(" ");
11 |
12 | for (String el2 : secondArray) {
13 |
14 | for (String el1 : firstArray) {
15 | if (el2.equals(el1)) {
16 | System.out.print(el1 + " ");
17 | }
18 | }
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/01. Basic Syntax, Conditional Statements and Loops - Lab/StudentInformation_01.java:
--------------------------------------------------------------------------------
1 | package BasicsOverview;
2 |
3 | import java.util.Scanner;
4 | public class StudentInformation_01 {
5 | public static void main(String[] args) {
6 | Scanner scanner = new Scanner(System.in);
7 | String name = scanner.nextLine(); //име на студента
8 | int age = Integer.parseInt(scanner.nextLine()); //възраст на судента
9 | double averageGrade = Double.parseDouble(scanner.nextLine()); //средна оценка на студента
10 |
11 | System.out.printf("Name: %s, Age: %d, Grade: %.2f", name, age, averageGrade);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/08. Text Processing - Exercise/CaesarCipher_04.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class CaesarCipher_04 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | String text = scanner.nextLine();
10 |
11 | StringBuilder encryptedText = new StringBuilder();
12 |
13 | for (char symbol : text.toCharArray()) {
14 | // 'A' -> 'D'
15 | char encryptedSymbol = (char) (symbol + 3);
16 | encryptedText.append(encryptedSymbol);
17 | }
18 |
19 | System.out.println(encryptedText);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/02. Data Types and Variables - Exercise/IntegerOperations_01.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class IntegerOperations_01 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int number1 = Integer.parseInt(scanner.nextLine());
10 | int number2 = Integer.parseInt(scanner.nextLine());
11 | int number3 = Integer.parseInt(scanner.nextLine());
12 | int number4 = Integer.parseInt(scanner.nextLine());
13 |
14 | // Формула: ((n1 + n2) / n3) * n4
15 | System.out.println(((number1 + number2) / number3) * number4);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/08. Text Processing - Lab/RepeatStrings_02.java:
--------------------------------------------------------------------------------
1 | package textProcessing;
2 |
3 | import java.util.Scanner;
4 |
5 | public class RepeatStrings_02 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | String [] texts = scanner.nextLine().split(" ");
10 |
11 | for (String text : texts) {
12 | int length = text.length(); //дължина на текста = брой символи в текст
13 | /*for (int count = 1; count <= length; count++) {
14 | System.out.print(text);
15 | }*/
16 | System.out.println(text.repeat(length));
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/01. Basic Syntax, Conditional Statements and Loops - Lab/SumOddNumbers_09.java:
--------------------------------------------------------------------------------
1 | package BasicsOverview;
2 |
3 | import java.sql.SQLOutput;
4 | import java.util.Scanner;
5 |
6 | public class SumOddNumbers_09 {
7 | public static void main(String[] args) {
8 | Scanner scanner = new Scanner(System.in);
9 | int n = Integer.parseInt(scanner.nextLine());
10 | int sum = 0;
11 |
12 | int number = 1;
13 | for (int count = 1; count <= n; count++) {
14 | System.out.println(number);
15 | sum += number;
16 | number += 2;
17 | }
18 |
19 | System.out.println("Sum: " + sum);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/06. Objects and Classes - Exercise/order_by_age_06/Person.java:
--------------------------------------------------------------------------------
1 | package order_by_age_06;
2 |
3 | public class Person {
4 |
5 | // 1. Fields
6 | private String name;
7 | private String id;
8 | private int age;
9 |
10 | // 2. Constructor
11 | public Person(String name, String id, int age) {
12 | this.name = name;
13 | this.id = id;
14 | this.age = age;
15 | }
16 |
17 | // 3. Methods
18 | public String getName() {
19 | return this.name;
20 | }
21 |
22 | public String getId() {
23 | return this.id;
24 | }
25 |
26 | public int getAge() {
27 | return this.age;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/03. Arrays - Lab/Demo/Demo2.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class Demo2 {
4 | public static void main(String[] args) {
5 | //създаваме масива
6 | String [] names = new String[10]; //[null, null, null, null, null, null, null, null, null, null]
7 | names[0] = "Desi";//["Desi", null, null, null, null, null, null, null, null, null]
8 | names[1] = "Ivan";//["Desi", "Ivan", null, null, null, null, null, null, null, null]
9 | names[2] = "Miroslav";//["Desi", "Ivan", "Miroslav", null, null, null, null, null, null, null]
10 | //валидни позиции: >= 0 и < дължина
11 | System.out.println(names[8]);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/02. Data Types and Varibles - Lab/CharsToString_06.java:
--------------------------------------------------------------------------------
1 | package DataTypes;
2 |
3 | import java.util.Scanner;
4 |
5 | public class CharsToString_06 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | char firstSymbol = scanner.nextLine().charAt(0);
10 | char secondSymbol = scanner.nextLine().charAt(0);
11 | char thirdSymbol = scanner.nextLine().charAt(0);
12 |
13 | //начин 1
14 | //System.out.println("" + firstSymbol + secondSymbol + thirdSymbol);
15 |
16 | //начин 2
17 | System.out.printf("%c%c%c", firstSymbol, secondSymbol, thirdSymbol);
18 |
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/08. Text Processing - Lab/TextFilter_04.java:
--------------------------------------------------------------------------------
1 | package textProcessing;
2 |
3 | import java.util.Scanner;
4 |
5 | public class TextFilter_04 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | String[] forbiddenWords = scanner.nextLine().split(", ");
10 | String text = scanner.nextLine();
11 |
12 | for (String forbiddenWord : forbiddenWords) {
13 | //"mask" -> "****"
14 | String replaceWord = "*".repeat(forbiddenWord.length());
15 | text = text.replace(forbiddenWord, replaceWord);
16 | }
17 |
18 | System.out.println(text);
19 |
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/04. Methods - Lab/CalculateArea_06.java:
--------------------------------------------------------------------------------
1 | package Methods;
2 |
3 | import java.util.Scanner;
4 |
5 | public class CalculateArea_06 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int length = Integer.parseInt(scanner.nextLine());
10 | int width = Integer.parseInt(scanner.nextLine());
11 |
12 | int area = calculateArea(length, width);
13 | System.out.println(area);
14 | }
15 |
16 | //метод, който изчислява и връща лицето на правоъгълник
17 | public static int calculateArea(int length, int width) {
18 | int area = length * width;
19 | return area;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/02. Data Types and Varibles - Lab/CenturiesToMinutes_09.java:
--------------------------------------------------------------------------------
1 | package DataTypesAndVariables;
2 |
3 | import java.util.Scanner;
4 |
5 | public class CenturiesToMinutes_09 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | byte centuries = Byte.parseByte(scanner.nextLine());
10 | int years = centuries * 100;
11 | double days = years * 365.2422;
12 | double hours = days * 24;
13 | double minutes = hours * 60;
14 |
15 | System.out.printf("%d centuries = %d years = %.0f days = %.0f hours = %.0f minutes", centuries, years, days, hours, minutes);
16 |
17 |
18 |
19 |
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/01. Basic Syntax, Conditional Statements and Loops - Lab/DivisibleBy3_08.java:
--------------------------------------------------------------------------------
1 | package BasicsOverview;
2 |
3 | import java.util.Scanner;
4 |
5 | public class DivisibleBy3_08 {
6 | public static void main(String[] args) {
7 | //[1; 100] които се делят на 3
8 | //for цикъл
9 | //1. начало -> 1
10 | //2. край -> 100
11 | //3. какво повтарям -> проверка дали се дели на 3 -> принтирам
12 | //4. промяна -> +1
13 |
14 | for (int number = 1; number <= 100; number++) {
15 | if (number % 3 == 0) {
16 | //number се дели на 3
17 | System.out.println(number);
18 | }
19 | }
20 |
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/08. Text Processing - Exercise/ExtractFile_03.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class ExtractFile_03 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | //"C:\Internal\training-internal\Template.pptx"
10 | String path = scanner.nextLine();
11 |
12 | String[] elements = path.split("\\\\");
13 |
14 | String fileName = elements[elements.length - 1].split("\\.")[0];
15 | String fileExtension = elements[elements.length - 1].split("\\.")[1];
16 |
17 | System.out.println("File name: " + fileName);
18 | System.out.println("File extension: " + fileExtension);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/04. Methods - Exercise/SmallestOfThreeNumbers_01.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class SmallestOfThreeNumbers_01 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int firstNumber = Integer.parseInt(scanner.nextLine());
10 | int secondNumber = Integer.parseInt(scanner.nextLine());
11 | int thirdNumber = Integer.parseInt(scanner.nextLine());
12 |
13 | printSmallestNumber(firstNumber, secondNumber, thirdNumber);
14 | }
15 |
16 | public static void printSmallestNumber(int num1, int num2, int num3) {
17 |
18 | System.out.println(Math.min(Math.min(num1, num2), num3));
19 | }
20 | }
--------------------------------------------------------------------------------
/09. RegEx - Lab/MatchFullName_01.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 | import java.util.regex.Matcher;
3 | import java.util.regex.Pattern;
4 |
5 | public class MatchFullName_01 {
6 |
7 | public static void main(String[] args) {
8 |
9 | Scanner scanner = new Scanner(System.in);
10 |
11 | String text = scanner.nextLine();
12 |
13 | String regex = "\\b([A-Z][a-z]+) ([A-Z][a-z]+)";
14 | Pattern pattern = Pattern.compile(regex);
15 | Matcher matcher = pattern.matcher(text);
16 |
17 | //matcher.find() -> true/false Ако намери следващо съвпадение
18 | while (matcher.find()){
19 | System.out.print(matcher.group() + " ");
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/08. Text Processing - Exercise/ReplaceRepeatingChars_06.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class ReplaceRepeatingChars_06 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | String input = scanner.nextLine();
10 | StringBuilder textBulder = new StringBuilder(input);
11 |
12 | for (int position = 0; position < textBulder.length() - 1; position++) {
13 | if (textBulder.charAt(position) == textBulder.charAt(position + 1)) {
14 | textBulder.deleteCharAt(position + 1);
15 | position--;
16 | }
17 | }
18 |
19 | System.out.println(textBulder);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/02. Data Types and Varibles - Lab/ExactSumOfRealNumbers_03.java:
--------------------------------------------------------------------------------
1 | package DataTypes;
2 |
3 | import java.math.BigDecimal;
4 | import java.util.Scanner;
5 |
6 | public class ExactSumOfRealNumbers_03 {
7 | public static void main(String[] args) {
8 | Scanner scanner = new Scanner(System.in);
9 | int count = Integer.parseInt(scanner.nextLine());
10 |
11 | BigDecimal sum = new BigDecimal("0");
12 | for (int number = 1; number <= count; number++) { //всички числа от първото до последното
13 | BigDecimal value = new BigDecimal(scanner.nextLine()); //стойността на въведеното число
14 |
15 | sum = sum.add(value);
16 | }
17 |
18 | System.out.println(sum);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/02. Data Types and Variables - Exercise/WaterOverflow_07.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class WaterOverflow_07 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int n = Integer.parseInt(scanner.nextLine());
10 | int litters = 0;
11 |
12 | for (int i = 1; i <= n; i++) {
13 |
14 | int pouredLiters = Integer.parseInt(scanner.nextLine());
15 | litters += pouredLiters;
16 |
17 | if (litters > 255) {
18 | System.out.println("Insufficient capacity!");
19 | litters -= pouredLiters;
20 | }
21 | }
22 |
23 | System.out.println(litters);
24 | }
25 | }
--------------------------------------------------------------------------------
/02. Data Types and Variables - Exercise/PrintPartOfAsciiTable_05.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class PrintPartOfAsciiTable_05 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int n = Integer.parseInt(scanner.nextLine());
10 |
11 | //{a-n}{a-n}{a-n}
12 | for (char letter1 = 'a'; letter1 < 'a' + n; letter1++) {
13 |
14 | for (char letter2 = 'a'; letter2 < 'a' + n; letter2++) {
15 |
16 | for (char letter3 = 'a'; letter3 < 'a' + n; letter3++) {
17 |
18 | System.out.printf("%c%c%c\n", letter1, letter2, letter3);
19 | }
20 | }
21 | }
22 |
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/02. Data Types and Varibles - Lab/RefactorVolumeOfPyramid_11.java:
--------------------------------------------------------------------------------
1 | package DataTypesAndVariables;
2 |
3 | import java.util.Scanner;
4 |
5 | public class RefactorVolumeOfPyramid_11 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 | System.out.print("Length: ");
9 | double length = Double.parseDouble(scanner.nextLine());
10 | System.out.print("Width: ");
11 | double width = Double.parseDouble(scanner.nextLine());
12 | System.out.print("Height: ");
13 | double height = Double.parseDouble(scanner.nextLine());
14 | double volume = (length * width * height) / 3;
15 | System.out.printf("Pyramid Volume: %.2f", volume);
16 |
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/06. Objects and Classes - Exercise/students_04/Student.java:
--------------------------------------------------------------------------------
1 | package students_04;
2 |
3 | public class Student {
4 |
5 | // 1. Fields
6 | private String firstName;
7 | private String lastName;
8 | private double grade;
9 |
10 | // 2. Constructor
11 | public Student(String firstName, String lastName, double grade) {
12 | this.firstName = firstName;
13 | this.lastName = lastName;
14 | this.grade = grade;
15 | }
16 |
17 | // 3. Methods
18 | public String getFirstName() {
19 | return this.firstName;
20 | }
21 |
22 | public String getLastName() {
23 | return this.lastName;
24 | }
25 |
26 | public double getGrade() {
27 | return this.grade;
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/03. Arrays - Exercise/Train_1.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class Train_1 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int wagonsCount = Integer.parseInt(scanner.nextLine());
10 | int[] wagons = new int[wagonsCount];
11 |
12 | for (int wagon = 0; wagon < wagonsCount; wagon++) {
13 | int group = Integer.parseInt(scanner.nextLine());
14 | wagons[wagon] = group;
15 | }
16 |
17 | int sum = 0;
18 |
19 | for (int number : wagons) {
20 | System.out.print(number + " ");
21 | sum += number;
22 | }
23 |
24 | System.out.println();
25 | System.out.println(sum);
26 | }
27 | }
--------------------------------------------------------------------------------
/03. Arrays - Lab/EvenOddSubtraction_05.java:
--------------------------------------------------------------------------------
1 | package Arrays;
2 |
3 | import java.util.Arrays;
4 | import java.util.Scanner;
5 |
6 | public class EvenOddSubtraction_05 {
7 | public static void main(String[] args) {
8 | Scanner scanner = new Scanner(System.in);
9 |
10 | int[] numbers = Arrays.stream(scanner.nextLine().split(" "))
11 | .mapToInt(Integer::parseInt)
12 | .toArray();
13 |
14 | int odd = 0;
15 | int even = 0;
16 |
17 | for (int number : numbers) {
18 | if (number % 2 == 0) {
19 | even += number;
20 | } else {
21 | odd += number;
22 | }
23 |
24 | }
25 |
26 | System.out.println(even - odd);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/04. Methods - Exercise/VowelsCount_02.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class VowelsCount_02 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | String text = scanner.nextLine().toLowerCase();
10 |
11 | printVowelsCount(text);
12 | }
13 |
14 | public static void printVowelsCount(String text) {
15 |
16 | int countVowels = 0;
17 |
18 | for (char letter : text.toCharArray()) {
19 | // a, e, i, o, u
20 | if (letter == 'a' || letter == 'e' || letter == 'i' || letter == 'o' || letter == 'u') {
21 | countVowels++;
22 | }
23 | }
24 |
25 | System.out.println(countVowels);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/01. Basic Syntax, Conditional Statements and Loops - Exercise/Ages_01.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class Ages_01 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int age = Integer.parseInt(scanner.nextLine());
10 |
11 | if (age >= 0 && age <= 2) {
12 | System.out.println("baby");
13 | } else if (age >= 3 && age <= 13) {
14 | System.out.println("child");
15 | } else if (age >= 14 && age <= 19) {
16 | System.out.println("teenager");
17 | } else if (age >= 20 && age <= 65) {
18 | System.out.println("adult");
19 | } else {
20 | System.out.println("elder");
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/02. Data Types and Variables - Exercise/SumDigits_02.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class SumDigits_02 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int number = Integer.parseInt(scanner.nextLine());
10 | int sum = 0;
11 |
12 | // Повтарям: числото > 0
13 | // 1. Вземам последната цифра от числото (числото % 10)
14 | // 2. Прибавям последната цифра към сумата (sum += lastDigit)
15 | // 3. Премахваме последната цифра от числото (числото / 10)
16 |
17 | while (number > 0) {
18 | int lastDigit = number % 10;
19 | sum += lastDigit;
20 | number /= 10;
21 | }
22 |
23 | System.out.println(sum);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/01. Basic Syntax, Conditional Statements and Loops - Lab/BackIn30Minutes_04.java:
--------------------------------------------------------------------------------
1 | package BasicsOverview;
2 |
3 | import java.util.Scanner;
4 |
5 | public class BackIn30Minutes_04 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 | int hour = Integer.parseInt(scanner.nextLine());
9 | int minutes = Integer.parseInt(scanner.nextLine());
10 |
11 | int totalMinutes = hour * 60 + minutes;
12 | int totalMinutesBack = totalMinutes + 30;
13 |
14 | int resultHour = totalMinutesBack / 60;
15 | int resultMinutes = totalMinutesBack % 60;
16 |
17 | if (resultHour > 23) {
18 | resultHour = 0;
19 | }
20 |
21 | System.out.printf("%d:%02d", resultHour, resultMinutes);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/06. Objects and Classes - Lab/songs/Song.java:
--------------------------------------------------------------------------------
1 | package songs;
2 |
3 | public class Song {
4 | //характеристики (field): Type List, Name and Time (3:23)
5 | private String typeList;
6 | private String name;
7 | private String time;
8 |
9 | //конструктор -> създава обект от класа
10 | public Song (String typeList, String name, String time) {
11 | //нов празен обект
12 | this.typeList = typeList;
13 | this.name = name;
14 | this.time = time;
15 | }
16 |
17 | //getter за полето name -> върне стойността на полето name
18 | public String getName() {
19 | return name;
20 | }
21 |
22 | //getter за полето typeList -> върне стойността на полето typeList
23 | public String getTypeList() {
24 | return typeList;
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/08. Text Processing - Lab/ReverseStringWithStringBuilder_01.java:
--------------------------------------------------------------------------------
1 | package textProcessing;
2 |
3 | import java.util.Scanner;
4 |
5 | public class ReverseStringWithStringBuilder_01 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | String input = scanner.nextLine(); //входни данни -> дума или "end"
10 |
11 | while (!input.equals("end")) {
12 | //input -> дума
13 | //input = "hello"
14 | StringBuilder sb = new StringBuilder(input);
15 | sb.reverse();
16 |
17 | //входяща дума -> input
18 | //обърната дума -> reverseWord
19 | System.out.println(input + " = " + sb.toString());
20 |
21 | input = scanner.nextLine();
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/06. Objects and Classes - Lab/RandomizeWords_01.java:
--------------------------------------------------------------------------------
1 | import java.util.Random;
2 | import java.util.Scanner;
3 |
4 | public class RandomizeWords_01 {
5 | public static void main(String[] args) {
6 | Scanner scanner = new Scanner(System.in);
7 |
8 | String[] wordsArr = scanner.nextLine().split(" ");
9 |
10 | Random random = new Random();
11 |
12 | for (int i = 0; i < wordsArr.length; i++) {
13 | int rndIndexX = random.nextInt(wordsArr.length);
14 | int rndIndexY = random.nextInt(wordsArr.length);
15 |
16 | String oldWord = wordsArr[rndIndexX];
17 | wordsArr[rndIndexX] = wordsArr[rndIndexY];
18 | wordsArr[rndIndexY] = oldWord;
19 | }
20 |
21 | System.out.println(String.join(System.lineSeparator(), wordsArr));
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/04. Methods - Lab/PrintingTriangle_03.java:
--------------------------------------------------------------------------------
1 | package Methods;
2 |
3 | import java.util.Scanner;
4 |
5 | public class PrintingTriangle_03 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int input = Integer.parseInt(scanner.nextLine());
10 |
11 | printTriangle(input);
12 | }
13 |
14 | public static void printTriangle (int num) {
15 | for (int i = 1; i <= num; i++) {
16 | printLine(1, i);
17 | }
18 |
19 | for (int i = num - 1; i >= 1; i--) {
20 | printLine(1, i);
21 | }
22 | }
23 |
24 | public static void printLine(int start, int end) {
25 | for (int i = start; i <= end; i++) {
26 | System.out.print(i + " ");
27 | }
28 | System.out.println();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/05. Lists - Exercise/AppendArrays_07.java:
--------------------------------------------------------------------------------
1 | import java.util.Arrays;
2 | import java.util.Collections;
3 | import java.util.List;
4 | import java.util.Scanner;
5 | import java.util.stream.Collectors;
6 |
7 | public class AppendArrays_07 {
8 |
9 | public static void main(String[] args) {
10 |
11 | Scanner scanner = new Scanner(System.in);
12 |
13 | List elements = Arrays.stream(scanner.nextLine().split("\\|")).collect(Collectors.toList());
14 |
15 | Collections.reverse(elements);
16 |
17 | String output = elements.toString()
18 | .replace("[", "")
19 | .replace("]", "")
20 | .replace(",", "")
21 | .replaceAll("\\s+", " ")
22 | .trim();
23 |
24 | //7 8 4 5 6 1 2 3
25 | System.out.println(output);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/04. Methods - Exercise/AddAndSubtract_05.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class AddAndSubtract_05 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int firstNumber = Integer.parseInt(scanner.nextLine());
10 | int secondNumber = Integer.parseInt(scanner.nextLine());
11 | int thirdNumber = Integer.parseInt(scanner.nextLine());
12 |
13 | int sum = sumTwoNumbers(firstNumber, secondNumber);
14 | int result = subtractTwoNumbers(sum, thirdNumber);
15 |
16 | System.out.println(result);
17 | }
18 |
19 | public static int sumTwoNumbers(int num1, int num2) {
20 |
21 | return num1 + num2;
22 | }
23 |
24 | public static int subtractTwoNumbers(int num1, int num2) {
25 |
26 | return num1 - num2;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/05. Lists - Lab/GaussTrick_02.java:
--------------------------------------------------------------------------------
1 | package Lists;
2 |
3 | import java.util.Scanner;
4 | import java.util.Arrays;
5 | import java.util.List;
6 | import java.util.stream.Collectors;
7 |
8 |
9 | public class GaussTrick_02 {
10 | public static void main(String[] args) {
11 | Scanner scanner = new Scanner(System.in);
12 |
13 | List numbers = Arrays.stream(scanner.nextLine().split(" "))
14 | .map(Integer::parseInt).collect(Collectors.toList());
15 |
16 | int iteration = numbers.size() / 2;
17 | for (int i = 0; i < iteration; i++) {
18 | numbers.set(i, numbers.get(i) + numbers.get(numbers.size() - 1));
19 | numbers.remove(numbers.size() - 1);
20 | }
21 |
22 | for (int number : numbers) {
23 | System.out.print(number + " ");
24 | }
25 |
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/07. Maps, Lambda, Stream API - Lab/WordFilter_04.java:
--------------------------------------------------------------------------------
1 | package maps;
2 |
3 | import java.util.Arrays;
4 | import java.util.Scanner;
5 |
6 | public class WordFilter_04 {
7 | public static void main(String[] args) {
8 | Scanner scanner = new Scanner(System.in);
9 | String[] words = Arrays.stream(scanner.nextLine().split(" ")) //["kiwi", "orange", "banana", "apple"]
10 | .filter(word -> word.length() % 2 == 0) //["kiwi", "orange", "banana"]
11 | .toArray(String[] :: new);
12 |
13 | //1 начин -> StreamAPI
14 | //words = ["kiwi", "orange", "banana"]
15 | //Arrays.stream(words).forEach(word -> System.out.println(word));
16 |
17 | //2 начин -> foreach
18 | for (String word : words) {
19 | System.out.println(word);
20 | }
21 |
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/08. Text Processing - Exercise/MultiplyBigNumber_05.java:
--------------------------------------------------------------------------------
1 | import java.math.BigInteger;
2 | import java.util.Scanner;
3 |
4 | public class MultiplyBigNumber_05 {
5 |
6 | public static void main(String[] args) {
7 |
8 | Scanner scanner = new Scanner(System.in);
9 |
10 | String firstNumber = scanner.nextLine();
11 | String secondNumber = scanner.nextLine();
12 |
13 | BigInteger number1 = new BigInteger(firstNumber);
14 | BigInteger number2 = new BigInteger(secondNumber);
15 |
16 | // Умножение
17 | System.out.println(number1.multiply(number2));
18 |
19 | // // Събиране
20 | // System.out.println(number1.add(number2));
21 | // // Изваждане
22 | // System.out.println(number1.subtract(number2));
23 | // // Деление
24 | // System.out.println(number1.divide(number2));
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/01. Basic Syntax, Conditional Statements and Loops - Lab/EvenNumber_11.java:
--------------------------------------------------------------------------------
1 | package BasicsOverview;
2 |
3 | import java.util.Scanner;
4 |
5 | public class EvenNumber_11 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | //while
10 | //повтаряме: въвеждаме цяло число
11 | //стоп: число е четно
12 | //продължаваме: число е нечетно
13 |
14 | int number = Integer.parseInt(scanner.nextLine());
15 |
16 | while (number % 2 != 0) {
17 | //нечетно число
18 | System.out.println("Please write an even number.");
19 |
20 | //прочитаме
21 | number = Integer.parseInt(scanner.nextLine());
22 | }
23 |
24 | //четно число -> прекратили цикъла
25 | System.out.println("The number is: " + Math.abs(number));
26 |
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/03. Arrays - Exercise/CondenseArrayToNumber_07.java:
--------------------------------------------------------------------------------
1 | import java.util.Arrays;
2 | import java.util.Scanner;
3 |
4 | public class CondenseArrayToNumber_07 {
5 |
6 | public static void main(String[] args) {
7 |
8 | Scanner scanner = new Scanner(System.in);
9 |
10 | int[] numbers = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
11 |
12 | if (numbers.length == 1) {
13 | System.out.print(numbers[0]);
14 | return;
15 | }
16 |
17 | while (numbers.length > 1) {
18 |
19 | int[] condensed = new int[numbers.length - 1];
20 |
21 | for (int i = 0; i < condensed.length; i++) {
22 | condensed[i] = numbers[i] + numbers[i + 1];
23 | }
24 |
25 | numbers = condensed;
26 | }
27 |
28 | System.out.println(numbers[0]);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/01. Basic Syntax, Conditional Statements and Loops - Exercise/PrintAndSum_04.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class PrintAndSum_04 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int startNumber = Integer.parseInt(scanner.nextLine());
10 | int endNumber = Integer.parseInt(scanner.nextLine());
11 |
12 | int sum = 0;
13 |
14 | for (int number = startNumber; number <= endNumber; number++) {
15 |
16 | System.out.print(number + " ");
17 | sum += number;
18 | }
19 |
20 | // int number = startNumber;
21 | // while (number <= endNumber) {
22 | //
23 | // System.out.print(number + " ");
24 | // sum += number;
25 | //
26 | // number++;
27 | // }
28 |
29 | System.out.println("\nSum: " + sum);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/02. Data Types and Varibles - Lab/SpecialNumber_10.java:
--------------------------------------------------------------------------------
1 | package DataTypesAndVariables;
2 |
3 | import java.util.Scanner;
4 |
5 | public class SpecialNumber_10 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 | int n = Integer.parseInt(scanner.nextLine());
9 | for (int number = 1; number <= n; number++) {
10 | int sum = 0;
11 | int currentNumber = number;
12 | while (currentNumber != 0) {
13 | int lastDigit = currentNumber % 10;
14 | sum += lastDigit;
15 | currentNumber /= 10;
16 | }
17 |
18 | if (sum == 5 || sum == 7 || sum == 11) {
19 | System.out.println(number + " -> True");
20 | } else {
21 | System.out.println(number + " -> False");
22 | }
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/03. Arrays - Lab/PrintNumbersInReverseOrder_02.java:
--------------------------------------------------------------------------------
1 | package Arrays;
2 |
3 | import java.util.Scanner;
4 |
5 | public class PrintNumbersInReverseOrder_02 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 | //1. съхраняваме числата в масив
9 | int count = Integer.parseInt(scanner.nextLine()); //брой на числата, с които ще работим
10 | int [] numbers = new int[count];
11 |
12 | for (int position = 0; position <= numbers.length - 1; position++) {
13 | numbers[position] = Integer.parseInt(scanner.nextLine());
14 | }
15 |
16 | //2. отпечтваме в обратен ред
17 | //[10, 20, 30]
18 | //обратен ред: последната позиция към първата
19 | for (int position = numbers.length - 1; position >= 0; position--) {
20 | System.out.print(numbers[position] + " ");
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/06. Objects and Classes - Exercise/articles_02/Article.java:
--------------------------------------------------------------------------------
1 | package articles_02;
2 |
3 | public class Article {
4 |
5 | // 1. Fields
6 | private String title;
7 | private String content;
8 | private String author;
9 |
10 | // 2. Constructor
11 | public Article(String title, String content, String author) {
12 | this.title = title;
13 | this.content = content;
14 | this.author = author;
15 | }
16 |
17 | // 3. Methods
18 | public void edit(String newContent) {
19 | this.content = newContent;
20 | }
21 |
22 | public void changeAuthor(String newAuthor) {
23 | this.author = newAuthor;
24 | }
25 |
26 | public void rename(String newTitle) {
27 | this.title = newTitle;
28 | }
29 |
30 | public String toString() {
31 | return String.format("%s - %s: %s", this.title, this.content, this.author);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/04. Methods - Lab/MultiplyEvensByOdds_10.java:
--------------------------------------------------------------------------------
1 | package Methods;
2 |
3 | import java.util.Scanner;
4 |
5 | public class MultiplyEvensByOdds_10 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int number = Integer.parseInt(scanner.nextLine());
10 | int [] sums = getSumEvenDddDigits(Math.abs(number));
11 |
12 | System.out.println(sums[0] * sums[1]);
13 | }
14 |
15 | private static int[] getSumEvenDddDigits(int number) {
16 | int sumEven = 0;
17 | int sumOdd = 0;
18 |
19 | while (number > 0) {
20 | int lastDigit = number % 10;
21 | if (lastDigit % 2 == 0) {
22 | sumEven += lastDigit;
23 | } else {
24 | sumOdd += lastDigit;
25 | }
26 | number /= 10;
27 | }
28 | return new int[] {sumEven, sumOdd};
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/01. Basic Syntax, Conditional Statements and Loops - Exercise/Orders_09.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class Orders_09 {
4 | public static void main(String[] args) {
5 |
6 | Scanner scanner = new Scanner(System.in);
7 |
8 | int orders = Integer.parseInt(scanner.nextLine());
9 | double money = 0;
10 |
11 | for (int order = 1; order <= orders; order++) {
12 |
13 | double pricePerCapsule = Double.parseDouble(scanner.nextLine());
14 | int daysInMonth = Integer.parseInt(scanner.nextLine());
15 | int capsulesCount = Integer.parseInt(scanner.nextLine());
16 |
17 | double orderPrice = ((daysInMonth * capsulesCount) * pricePerCapsule);
18 | money += orderPrice;
19 |
20 | System.out.printf("The price for the coffee is: $%.2f%n", orderPrice);
21 | }
22 |
23 | System.out.printf("Total: $%.2f", money);
24 | }
25 | }
--------------------------------------------------------------------------------
/04. Methods - Exercise/FactorialDivision_08.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class FactorialDivision_08 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int firstNumber = Integer.parseInt(scanner.nextLine());
10 | int secondNumber = Integer.parseInt(scanner.nextLine());
11 |
12 | long firstNumberFactorial = calculateFactorial(firstNumber);
13 | long secondNumberFactorial = calculateFactorial(secondNumber);
14 |
15 | double result = firstNumberFactorial * 1.0 / secondNumberFactorial;
16 |
17 | System.out.printf("%.2f", result);
18 | }
19 |
20 | public static long calculateFactorial(int number) {
21 |
22 | // 5! = 1 * 2 * 3 * 4 * 5
23 | long fact = 1;
24 | for (int i = 2; i <= number; i++) {
25 | fact *= i;
26 | }
27 |
28 | return fact;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/01. Basic Syntax, Conditional Statements and Loops - Lab/ForeignLanguages_06.java:
--------------------------------------------------------------------------------
1 | package BasicsOverview;
2 |
3 | import java.util.Scanner;
4 |
5 | public class ForeignLanguages_06 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | String country = scanner.nextLine();
10 | //"USA" or "England" -> English
11 | //"Spain" or "Argentina" or "Mexico" -> Spanish
12 | //other -> unknown
13 |
14 | switch (country) {
15 | case "USA":
16 | case "England":
17 | System.out.println("English");
18 | break;
19 | case "Spain":
20 | case "Argentina":
21 | case "Mexico":
22 | System.out.println("Spanish");
23 | break;
24 | default:
25 | System.out.println("unknown");
26 | break;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/02. Data Types and Varibles - Lab/RefactorSpecialNumbers_12.java:
--------------------------------------------------------------------------------
1 | package DataTypesAndVariables;
2 |
3 | import java.util.Scanner;
4 |
5 | public class RefactorSpecialNumbers_12 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 | int count = Integer.parseInt(scanner.nextLine());
9 |
10 | for (int number = 1; number <= count; number++) {
11 | int sum = 0;
12 | int currentNumber = number;
13 | while (currentNumber > 0) {
14 | sum += currentNumber % 10;
15 | currentNumber = currentNumber / 10;
16 | }
17 | boolean isTrue = (sum == 5) || (sum == 7) || (sum == 11);
18 | if (isTrue) {
19 | System.out.printf("%d -> True%n", number);
20 | } else {
21 | System.out.printf("%d -> False%n", number);
22 | }
23 |
24 | }
25 |
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/HTML and CSS Basics - Common Lection/lists.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | List Items
6 |
7 |
8 |
9 |
List item 1
10 |
11 |
Nested item 1.1
12 |
Nested item 1.2
13 |
14 |
15 |
16 |
List item 2
17 |
18 |
Nested item 2.1
19 |
Nested item 2.2
20 |
21 |
Nested Item 2.2.1
22 |
Nested Item 2.2.2
23 |
Nested Item 2.2.3
24 |
25 |
26 |
Nested item 2.3
27 |
28 |
29 |
30 |
List item 3
31 |
32 |
33 |
--------------------------------------------------------------------------------
/03. Arrays - Lab/DayOfWeek_01.java:
--------------------------------------------------------------------------------
1 | package Arrays;
2 |
3 | import java.util.Scanner;
4 |
5 | public class DayOfWeek_01 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | //1 -> "Monday"
10 | //2 -> "Tuesday"
11 | //3 -> "Wednesday"
12 | //4 -> "Thursday"
13 | //5 -> "Friday"
14 | //6 -> "Saturday"
15 | //7 -> "Sunday"
16 | //other -> Invalid day!
17 | int numberDay = Integer.parseInt(scanner.nextLine());
18 |
19 | String [] daysOfWeek = {"Monday", "Tuesday", "Wednesday", "Thursday",
20 | "Friday", "Saturday", "Sunday"};
21 |
22 | if (numberDay >= 1 && numberDay <= 7) {
23 | //отпечатваме деня на текущия номер
24 | System.out.println(daysOfWeek[numberDay - 1]);
25 | } else {
26 | System.out.println("Invalid day!");
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/01. Basic Syntax, Conditional Statements and Loops - Exercise/Division_02.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class Division_02 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | int number = Integer.parseInt(scanner.nextLine());
10 |
11 | if (number % 10 == 0) {
12 | System.out.println("The number is divisible by 10");
13 | } else if (number % 7 == 0) {
14 | System.out.println("The number is divisible by 7");
15 | } else if (number % 6 == 0) {
16 | System.out.println("The number is divisible by 6");
17 | } else if (number % 3 == 0) {
18 | System.out.println("The number is divisible by 3");
19 | } else if (number % 2 == 0) {
20 | System.out.println("The number is divisible by 2");
21 | } else {
22 | System.out.println("Not divisible");
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/08. Text Processing - Lab/Substring_03.java:
--------------------------------------------------------------------------------
1 | package textProcessing;
2 |
3 | import java.util.Scanner;
4 |
5 | public class Substring_03 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | String firstText = scanner.nextLine();
10 | String secondText = scanner.nextLine();
11 |
12 | int index = secondText.indexOf(firstText);
13 | //firstText = "ice"
14 | //secondText = "kgb"
15 | //ако firstText се съдържа в secondText -> на коя позиция се намира
16 | //ако firstText НЕ СЕ СЪДЪРЖА в secondText -> -1
17 |
18 | while (index != -1) {
19 | //firstText го има secondText
20 | secondText = secondText.replace(firstText, "");
21 | //след премахването -> търсим дали имаме тази дума
22 | index = secondText.indexOf(firstText);
23 | }
24 |
25 | System.out.println(secondText);
26 |
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/04. Methods - Lab/Orders_05.java:
--------------------------------------------------------------------------------
1 | package Methods;
2 |
3 | import java.util.Scanner;
4 |
5 | public class Orders_05 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | String product = scanner.nextLine();
10 | int quantity = Integer.parseInt(scanner.nextLine());
11 | printPrice(product, quantity);
12 |
13 | }
14 |
15 | public static void printPrice(String product, int quantity) {
16 |
17 | switch (product) {
18 | case "coffee":
19 | System.out.printf("%.2f", quantity * 1.50);
20 | break;
21 | case "water":
22 | System.out.printf("%.2f", quantity * 1.00);
23 | break;
24 | case "coke":
25 | System.out.printf("%.2f", quantity * 1.40);
26 | break;
27 | case "snacks":
28 | System.out.printf("%.2f", quantity * 2.00);
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/09. RegEx - Lab/regex-cheatsheet.txt:
--------------------------------------------------------------------------------
1 | Quantity Modifier / Колко пъти искаме да се среща даден текст?
2 | + -> 1 или повече пъти
3 | * -> 0 или повече пъти
4 | ? -> 0 или 1 път
5 | {число} -> колко точно пъти
6 | {число1, } -> колко най-малко пъти
7 | {число1, число2} -> колко най-малко(число1) пъти и колко най-много(число2) пъти
8 |
9 | Regex:
10 | [a-z] -> 1 малка буква
11 | [A-Z] -> 1 главна буква
12 | [0-9] -> 1 цифра
13 | [abv] -> 1 символ, който е или 'а', или 'b', или 'v'
14 | [^abv] -> 1 символ, който е РАЗЛИЧЕН от 'а', от 'b' и от 'v'
15 | \w -> 1 символ, който може да е малка или главна буква, цифра, или _
16 | \W -> 1 символ, който РАЗЛИЧЕН от малка или главна буква, цифра, или _
17 | \d -> 1 цифра
18 | \D -> 1 символ РАЗЛИЧЕН от цифра
19 | \s -> 1 интервал
20 | \S -> 1 символ РАЗЛИЧЕН от интервал
21 | () -> обособяваме група
22 | (?) -> обособяваме група с име
23 | \b -> слагаме граница, която казва, че не искаме да има символи(букви/цифри) преди/след съвпадението, което е открито в текста.
--------------------------------------------------------------------------------
/03. Arrays - Exercise/MagicSum_08.java:
--------------------------------------------------------------------------------
1 | import java.util.Arrays;
2 | import java.util.Scanner;
3 |
4 | public class MagicSum_08 {
5 |
6 | public static void main(String[] args) {
7 |
8 | Scanner scanner = new Scanner(System.in);
9 |
10 | int[] numbers = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
11 | int magicSum = Integer.parseInt(scanner.nextLine());
12 |
13 | //1 7 6 2 19 23
14 |
15 | for (int position = 0; position < numbers.length - 1; position++) {
16 |
17 | int currentNumber = numbers[position];
18 |
19 | for (int nextPosition = position + 1; nextPosition <= numbers.length - 1; nextPosition++) {
20 |
21 | int nextNumber = numbers[nextPosition];
22 |
23 | if (currentNumber + nextNumber == magicSum) {
24 | System.out.printf("%d %d\n", currentNumber, nextNumber);
25 | }
26 | }
27 | }
28 |
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/08. Text Processing - Lab/Demo/DemoStringVsStringBuilder.java:
--------------------------------------------------------------------------------
1 | package textProcessing;
2 |
3 | import java.util.Scanner;
4 |
5 | public class DemoStringVsStringBuilder {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | //STRING VS STRING BUILDER
10 | //1. STRING BUILDER има повече вградени методи от STRING -> insert, delete, reverse
11 | //2. STRING BUILDER e по-бърз от STRING
12 |
13 | //бързина на долепяне в String
14 | String textExample = "";
15 | for (int i = 0; i < 1000000; i++) {
16 | textExample += "a";
17 | //textExample = textExample + "a";
18 | }
19 |
20 | System.out.println(textExample);
21 |
22 | //бързина на долепяне в StringBuilder
23 | StringBuilder sb = new StringBuilder(); //""
24 | for (int i = 0; i < 1000000; i++) {
25 | sb.append("a");
26 | }
27 |
28 | System.out.println(sb);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/06. Objects and Classes - Exercise/opinion_poll_03/Main.java:
--------------------------------------------------------------------------------
1 | package opinion_poll_03;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 | import java.util.Scanner;
6 |
7 | public class Main {
8 |
9 | public static void main(String[] args) {
10 |
11 | Scanner scanner = new Scanner(System.in);
12 |
13 | List people = new ArrayList<>();
14 | int n = Integer.parseInt(scanner.nextLine());
15 |
16 | for (int i = 1; i <= n; i++) {
17 |
18 | //"{name} {age}"
19 | String input = scanner.nextLine();
20 | String name = input.split(" ")[0];
21 | int age = Integer.parseInt(input.split(" ")[1]);
22 |
23 | Person person = new Person(name, age);
24 | if (age > 30) {
25 | people.add(person);
26 | }
27 | }
28 |
29 | for (Person person : people) {
30 | System.out.printf("%s - %d\n", person.getName(), person.getAge());
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/09. RegEx - Lab/MatchPhoneNumber_02.java:
--------------------------------------------------------------------------------
1 | import java.util.ArrayList;
2 | import java.util.List;
3 | import java.util.Scanner;
4 | import java.util.regex.Matcher;
5 | import java.util.regex.Pattern;
6 |
7 | public class MatchPhoneNumber_02 {
8 |
9 | public static void main(String[] args) {
10 |
11 | Scanner scanner = new Scanner(System.in);
12 |
13 | String text = scanner.nextLine();
14 |
15 | // 1. Създавам регекс
16 | String regex = "\\+359([ -])2\\1\\d{3}\\1\\d{4}\\b";
17 | // 2. Създавам шаблон
18 | Pattern pattern = Pattern.compile(regex);
19 | // 3. Създавам инструмент с помощта на който ще проверявам за съвпадения в прочетеният текст от конзолата
20 | Matcher matcher = pattern.matcher(text);
21 |
22 | List validNumbers = new ArrayList<>();
23 | while (matcher.find()){
24 | validNumbers.add(matcher.group());
25 | }
26 |
27 | System.out.println(String.join(", ", validNumbers));
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/04. Methods - Lab/Grades_02.java:
--------------------------------------------------------------------------------
1 | package Methods;
2 |
3 | import java.util.Scanner;
4 | import java.util.regex.Pattern;
5 |
6 | public class Grades_02 {
7 | public static void main(String[] args) {
8 | Scanner scanner = new Scanner(System.in);
9 |
10 | double grade = Double.parseDouble(scanner.nextLine());
11 | printGradeInWords(grade);
12 | }
13 | //метод, който отпечтва името на оценката
14 | public static void printGradeInWords(double grade) {
15 | if (grade >= 2.00 && grade <= 2.99) {
16 | System.out.println("Fail");
17 | } else if (grade >= 3.00 && grade <= 3.49) {
18 | System.out.println("Poor");
19 | } else if (grade >= 3.50 && grade <= 4.49) {
20 | System.out.println("Good");
21 | } else if (grade >= 4.50 && grade <= 5.49) {
22 | System.out.println("Very good");
23 | } else if (grade >= 5.50 && grade <= 6.00) {
24 | System.out.println("Excellent");
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/04. Methods - Exercise/PalindromeIntegers_09.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class PalindromeIntegers_09 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | String input = scanner.nextLine();
10 |
11 | while (!input.equals("END")) {
12 |
13 | System.out.println(isInputPalindrome(input));
14 | input = scanner.nextLine();
15 | }
16 | }
17 |
18 | public static boolean isInputPalindrome(String input) {
19 |
20 | //Viko
21 | //okiV
22 |
23 | //Начин 1:
24 | String reversedString = "";
25 | for (int index = input.length() - 1; index >= 0; index--) {
26 | reversedString += input.charAt(index);
27 | }
28 |
29 | //Начин 2:
30 | // StringBuilder builder = new StringBuilder(input);
31 | // String reversedString = builder.reverse().toString();
32 |
33 | return input.equals(reversedString);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/08. Text Processing - Exercise/StringExplosion_07.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class StringExplosion_07 {
4 |
5 | public static void main(String[] args) {
6 |
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | String input = scanner.nextLine();
10 | StringBuilder textBuilder = new StringBuilder(input);
11 |
12 | int totalStrength = 0;
13 |
14 | for (int position = 0; position < textBuilder.length(); position++) {
15 |
16 | char currentSymbol = textBuilder.charAt(position);
17 |
18 | if (currentSymbol == '>') {
19 | int explosionStrength = Integer.parseInt(textBuilder.charAt(position + 1) + "");
20 | totalStrength += explosionStrength;
21 | } else if (totalStrength > 0) {
22 | textBuilder.deleteCharAt(position);
23 | totalStrength--;
24 | position--;
25 | }
26 | }
27 |
28 | System.out.println(textBuilder);
29 | }
30 | }
--------------------------------------------------------------------------------
/08. Text Processing - Lab/ReverseString_01.java:
--------------------------------------------------------------------------------
1 | package textProcessing;
2 |
3 | import java.util.Scanner;
4 |
5 | public class ReverseString_01 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 |
9 | String input = scanner.nextLine(); //входни данни -> дума или "end"
10 | while (!input.equals("end")) {
11 | //input -> дума
12 | //input = "hello"
13 | String reverseWord = ""; //обърнатата дума
14 | for (int position = input.length() - 1; position >= 0; position--) {
15 | char currentSymbol = input.charAt(position);
16 | reverseWord = reverseWord + currentSymbol;
17 | //reverseWord += currentSymbol;
18 | }
19 |
20 | //входяща дума -> input
21 | //обърната дума -> reverseWord
22 | System.out.println(input + " = " + reverseWord);
23 |
24 | input = scanner.nextLine();
25 | }
26 |
27 |
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/04. Methods - Lab/SignOfIntegers_01.java:
--------------------------------------------------------------------------------
1 | package Methods;
2 |
3 | import java.util.Scanner;
4 |
5 | public class SignOfIntegers_01 {
6 | public static void main(String[] args) {
7 | Scanner scanner = new Scanner(System.in);
8 | int number = Integer.parseInt(scanner.nextLine());
9 | printTypeOfInteger(number);
10 |
11 | }
12 | //метод, който отпечатва вида на цялото число
13 | //< 0 -> negative
14 | //== 0 -> zero
15 | //> 0 -> positive
16 | //public static {тип на метода} {име на метод} ({параметри}) { }
17 | public static void printTypeOfInteger (int number) {
18 | if (number < 0) {
19 | //negative number
20 | System.out.printf("The number %d is negative.", number);
21 | } else if (number == 0) {
22 | //zero
23 | System.out.printf("The number %d is zero.", number);
24 | } else {
25 | //positive
26 | System.out.printf("The number %d is positive.", number);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/HTML and CSS Basics - Common Lection/wiki-page.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | The Brown Bear
6 |
7 |
8 |
The Brown Bear
9 |
The brown bear (Ursus arctos) is native to parts of northern Eurasia and North America.
10 | It's conservation status is currently "Least Concern". There are many subspecies within
11 | the brown bear species, including the Atlas bear and the Himalayan brown bear.