Advertisement
wingman007

Java2018IntroCheatSheet

Oct 21st, 2018 (edited)
1,185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 22.11 KB | None | 0 0
  1. // Да програмираш значи да описваш алгоритъм с формален език за програмиране. Алгоритми + данни = програми.
  2. // HelloWorld.java
  3. // javac HelloWorld.java
  4. // java HelloWorld
  5. // javac -d . HelloWorldPackage.java
  6. // java com.coolcsn.HelloWorldPackage
  7. // "C:\Program Files (x86)\Java\jdk1.8.0_192\bin\javac" HelloWorld.java
  8. // "C:\Program Files (x86)\Java\jdk1.8.0_192\bin\java" HelloWorld
  9. // sout + tab - prints System.out.println; Alt + Enter; Enter brak point, Start Debug, look down on the left step into
  10. // Ctrl + / - comment out, uncomment
  11. // ⌥ ⌘ / macOS or Ctrl + Shift + / - Block comments. Comment Uncomment
  12. // Refactor This using ⌃T (MacOS) or Shift+Ctrl+Alt+T (Windows)
  13. // Shift + F6 rename
  14. // Shift + F9 - Debug
  15. // Shoft + F10 - Rub
  16. // You can use ⌘N (macOS), or Alt+Insert (Windows/Linux) for the Generate menu and then select Constructor, Getter, Setter or Getter and Setter
  17.  
  18. // IntelyJ shortcuts: sout, fori + /t
  19.  
  20. package com.coolcsn;
  21. import java.util.*;
  22.  
  23. public class HelloWorld {
  24.  
  25.  
  26.     public static final String ANSI_RED_BACKGROUND = "\u001B[41m";
  27.     public static final String ANSI_RESET = "\u001B[0m";
  28.     public static final String ANSI_RED = "\u001B[31m";
  29.     public static final String ANSI_GREEN_BACKGROUND = "\u001B[42m";
  30.  
  31.  
  32.     public static void main(String[] args) throws java.io.IOException
  33.     {
  34.          // 1. Hello World
  35.          System.out.println("Hello World!");
  36.  
  37.         // 2. Primitive types. Strictly typed, static language
  38.         // 2.1. Integer. Default 0
  39.         byte myByte = -128; // 8 bits signed -128 to 127
  40.         short myShort = 23456; // 16 bits signed -2^15 to 2^15 -1
  41.         int myInt = 432423423; // 32 bits signed -2^31 to 2^31 -1
  42.         long myLong = 4321432423L; // 64 bits signed -2^63 to 2^63 -1
  43.         long maxLong = Long.MAX_VALUE;
  44.         System.out.println(maxLong);
  45.  
  46.  
  47.         // Literal
  48.         myShort = 034; // octal radix
  49.         System.out.println(myShort);
  50.  
  51.         // Hex Literal
  52.         myInt = 0xffab;
  53.         System.out.println(myInt);
  54.  
  55.  
  56.         // 2.2. Real
  57.         float myFloat = 2.3454324234324F; // 32 bits signed  7 symbols
  58.         double myDouble = 2.3454324234324D; // 64 bits signed 14 symbols
  59.  
  60.         System.out.println(myFloat);
  61.         System.out.println(myDouble);
  62.  
  63.         // 1.3 * 10^3
  64.         myDouble = 1.2e-1;
  65.         System.out.println(myDouble);
  66.  
  67.         // 2.3. Char
  68.         char myChar = 'S';
  69.  
  70.  
  71.         System.out.println((int)myChar);
  72.         System.out.println((char)84);
  73.  
  74.         myChar = '\u0041'; // A
  75.         myChar = '\u004E';
  76.         myChar = '\'';
  77.         System.out.println(myChar);
  78.  
  79.         System.out.println("\'Stoyancho\\Sharo\' \t 45 & | ");
  80.  
  81.         // 2.4.  String
  82.         String myString = "Stoyan"; // null
  83.  
  84.         // 2.5. Bool
  85.         boolean myBool = true; //
  86.  
  87.         // 2.6. Object
  88.         Object myObject = 5;
  89.  
  90.         Object obj = 5;
  91.         // obj = "Stoyancho";
  92.         System.out.println(obj);
  93.  
  94.         // Object n = 4;
  95.  
  96.         // System.out.println(obj + n);
  97.  
  98.         System.out.println("Hello World IDE");
  99.         System.out.println( 2 + 2);
  100.  
  101.         // 3. Operators
  102.         // 3.1 Arithmetics
  103.         int n = 25;
  104.         int m = 32;
  105.  
  106.         System.out.println(m + n); //57
  107.         System.out.println(m - n); // 7
  108.         System.out.println(m * n); // 800
  109.         System.out.println(m / n); // 1
  110.         System.out.println((double)m / n); // 1.28
  111.         System.out.println(m % n); // 7
  112.         // System.out.println(m++ + n); // 57
  113.         System.out.println(++m + n); // 58
  114.         // System.out.println(m-- + n); // 58
  115.         System.out.println(--m + n); // 57
  116.  
  117.  
  118.         // 3.2. Comparison
  119.         System.out.println(m > n); // true
  120.         System.out.println(m < n); // false
  121.         System.out.println(m <= n); // false
  122.         System.out.println(m >= n); // true
  123.         System.out.println(m != n); // true
  124.         System.out.println(m == n); // false
  125.  
  126.         // 3.3. Logical
  127.         boolean x = true;
  128.         boolean y = false;
  129.         System.out.println(x && y); // false
  130.         // | x     | y     | &&    | ||   | !X     |  X^Y  |
  131.         // | true  | true  | true  | true |  false | false |
  132.         // | true  | false | false | true |  false | true  |
  133.         // | false | true  | false | true |  true  | true  |
  134.         // | false | false | false | flase|  true  | flase |
  135.         System.out.println(x || y); // true
  136.         System.out.println(!x); // fasle
  137.         System.out.println(x ^ y); // true
  138.  
  139.         byte m1 = 3; //
  140.         byte n1 = 2;
  141.         System.out.println(m1 & n1); // 2
  142.         System.out.println(m1 | n1); // 3
  143.         System.out.println(~n1); // -1
  144.         System.out.println(n1 << 1); // 4
  145.         System.out.println(n1 >> 1); // 1
  146.         System.out.println(n1 >>> 1); // 1
  147.  
  148.         // 3.4. Asignment
  149.         m1 = 4;
  150.         m1 += 3; // m1 = m1 + 3;
  151.  
  152.         int t = 4;
  153.         t += 5; // t = t + 5;
  154.         t *= 2; // t = t * 2;
  155.         // =, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=, >>>=
  156.  
  157.         System.out.println(myString + myByte);
  158.  
  159.         System.out.println("Bojidare " + "Dineva " + 1);
  160.  
  161.         System.out.println((n1 > m1)? "Stoyan" : "Bojidara" );
  162.  
  163.         // Oreder of operations change with ()
  164.         System.out.println(((n1 + m1) * (n1 - m1++)) + --m1 / ( 5 + 2));
  165.  
  166.         System.out.println(obj.toString());
  167.  
  168.         // 4. Console
  169.         // %[argument_index$][flags][width][.precision]conversion
  170.         // argument_index - целочислен тип показващ позицията на аргумента от "аргументния списък".
  171.         // Първият аргумент се индикира с "1$", втория с "2$" и т.н.
  172.         // flags - поредица от символи които модифицират изходния формат.
  173.         // (Примерни ефекти са, показването на числото да бъде винаги със знак, слагането
  174.         // на скоби на отрицателните числа и т.н.) - Резултатът ще бъде ляво ориентиран;
  175.         // + Резултатът винаги ще включва знак (+, -); 0 Резултатът ще се отмести с нули;
  176.         // ( Резултатът ще затвори в скоби отрицателните числа
  177.         // width - неотрицателен целочислен тип показващ минималния брой символи, които трябва да се отпечатат.
  178.         // precision - неотрицателен целочислен тип ограничаващ броя на показваните символи.
  179.         // Този атрибут си променя поведението според conversion спецификатора. В случай на float определя броя цифри след запетаята.
  180.         // b, o, x, c, s, S, f, e, h, n
  181.         System.out.print("Enter your name: ");
  182.         System.out.print("Stoyan \n");
  183.  
  184.         String str = "Teodora";
  185.         String str1 = "Jivko";
  186.         System.out.printf("My name is %2$S and my name is %1$s . And I am a student! \n", str, str1);
  187.  
  188.         System.out.printf("%s \n", myInt);
  189.         System.out.printf("%12d \n", myInt);
  190.         System.out.printf("%12x \n", myInt);
  191.         System.out.printf("%12o \n", myInt);
  192.         System.out.printf("%+12.4f \n", -myFloat);
  193.  
  194.         // java.util.Date date = new java.util.Date();
  195.         Date date = new Date();
  196.         System.out.printf("%tY \n", date);
  197.         System.out.printf("%tm \n", date);
  198.         System.out.printf("%tB \n", date);
  199.         System.out.printf("%tA \n", date);
  200.         // System.out.printf("$tY, $tM \n", date);
  201.  
  202.         // Date myDate = new Date(2014, 02, 11); // deprecated
  203.         Date myDate1 = new GregorianCalendar(2014, Calendar.FEBRUARY, 11).getTime();
  204.  
  205.         java.util.Locale.setDefault(new java.util.Locale("bg", "BG"));
  206.         System.out.printf("%tA \n", date);
  207.         System.out.printf("Денят, в който бяхме съсипани: %1$tA %1$tH:%1$tM %1$tB-%1$tY.\n", new java.util.Date());
  208.  
  209.         // 4.2. System.in
  210.  
  211.         // Only one character
  212.         // System.out.print("Please enter your name: ");
  213.         // int ch = System.in.read();
  214.         // System.out.println("The first letter of your name has ASCII code: " + ch); // 83 System.out.println((char)ch);
  215.  
  216.         /* Uncomment to see System.in
  217.         // Old way of reading
  218.         int ch;
  219.         System.out.print("Please enter your name: ");
  220.         while ((ch = System.in.read()) != '\n') {
  221.              System.out.print((char) ch);
  222.         }
  223.  
  224.  
  225.         // !!!!!!!!!!! Use this Scanner !!!!!!!!!!!!!!!!!!!!
  226.         Scanner input = new java.util.Scanner(System.in);
  227.         // String
  228.         System.out.print("Please enter your name: ");
  229.         String firstName = input.nextLine();
  230.         // int
  231.         System.out.print("Please enter your Age: ");
  232.         int age = input.nextInt();
  233.         // Double
  234.         System.out.print("Please enter your Balance: ");
  235.         double balance = input.nextDouble();
  236.  
  237.         input.close();
  238.  
  239.         // Non formatted output
  240.         System.out.print("Your favorite number is " + (age * balance) + "\n");
  241.  
  242.         //
  243.         System.out.printf("Your favorite number is %f", (age * balance));
  244.  
  245.         System.out.println(ANSI_GREEN_BACKGROUND + ANSI_RED + "This text has a green background and red text!" + ANSI_RESET ); // + "\u001B[41m"
  246.         */
  247.  
  248.         // 5. Conditional logic. Условни конструкции
  249.         // 5.1.
  250.         if (n < m) {
  251.             System.out.print("n < m");
  252.         }
  253.  
  254.         // 5.2.
  255.         if (n > m ){
  256.             System.out.println("n > m");
  257.         }
  258.         else {
  259.             System.out.println("n < m");
  260.         }
  261.  
  262.  
  263.         // 5.3.
  264.         int testscore = 7;
  265.         char grade;
  266.  
  267.         if (testscore >= 90) {
  268.             grade = 'A';
  269.         } else if (testscore >= 80) {
  270.             grade = 'B';
  271.         } else if (testscore >= 70) {
  272.             grade = 'C';
  273.         } else if (testscore >= 60) {
  274.             grade = 'D';
  275.         } else {
  276.             grade = 'F';
  277.         }
  278.  
  279.         // switch
  280.         switch (m) {
  281.             case 3:
  282.             case 4 :
  283.                 System.out.println("m = 4 || m = 3");
  284.                 break;
  285.             case 5 :
  286.                 System.out.println("m = 5");
  287.                 break;
  288.             default:
  289.                 System.out.println("Deafult I couldn't guess!");
  290.                 break;
  291.         }
  292.  
  293.         // 6. Loops Цикли
  294.         // 6.1. While
  295.         int i = 0;
  296.         while (i < n){
  297.             System.out.println(i);
  298.             i++;
  299.         }
  300.  
  301.         // 6.2.
  302.         Scanner input = new java.util.Scanner(System.in);
  303.         int age = 0;
  304.         do {
  305.             System.out.print("Please, enter your age (0 to 120): ");
  306.             age = input.nextInt();
  307.         } while( age < 0 || age >= 120);
  308.  
  309.         // 5.3. for
  310.         for ( i = 0; i < 10; i++) {
  311.             System.out.print(i);
  312.         }
  313.  
  314.         // continue
  315.         System.out.println("------- odd ---------");
  316.         for ( i = 0; i < 10; i++) {
  317.             if (i % 2 == 0) continue;
  318.             System.out.println(i);
  319.         }
  320.  
  321.  
  322.         // break
  323.         int prime = 46;
  324.  
  325.         for ( i = 2; i < prime; i++) {
  326.             if (prime % i == 0 ) {
  327.                 System.out.println("The number is NOT prime");
  328.                 break;
  329.             }
  330.             // System.out.println(i);
  331.         }
  332.  
  333.         System.out.println();
  334.         // 5.4. Foreach. Douglas Addams
  335.         int[] myArray = {23, 42, 324, 65, 76};
  336.         for (int j : myArray) {
  337.             System.out.println(j);
  338.         }
  339.  
  340.         // 7. Arrays. Нареда/индексирана последователност от еднотипни елементи
  341.         // 7.1. Single dimension
  342.         int[] myIntArray = new int[5];
  343.         myIntArray[0] = 0;
  344.         myIntArray[3] = 3;
  345.  
  346.         for (i = 0; i < myIntArray.length; i++){
  347.             System.out.printf("myIntArray[%1$d] = %2$d \n", i, myIntArray[i]);
  348.         }
  349.  
  350.         String[] students = {"Iliya", "Jivko", "Nasko", "Teodora"};
  351.  
  352.         // 7.2. Multi dimension
  353.         int[][] twoDimentionalArray;
  354.         int[][][] threeDimentionalArray;
  355.  
  356.         int[][] matrix = {
  357.                 {1, 2, 3, 4}, // row 0 values
  358.                 {5, 6, 7, 8}, // row 1 values
  359.         };
  360.         // The matrix size is 2 x 4 (2 rows, 4 cols)
  361.  
  362.         for (int row = 0; row < matrix.length; row++) {
  363.             for (int col = 0; col < matrix[0].length; col++) {
  364.                 System.out.printf("matrix[%1$d][%2$d] = %3$d \n", row, col, matrix[row][col]);
  365.             }
  366.             System.out.println();
  367.         }
  368.  
  369.         int[][] matrixDefined = new int[2][3];
  370.  
  371.         String[] myStringArray = new String[5];
  372.         for (i = 0; i < myStringArray.length; i++){
  373.             System.out.println(myStringArray[i]);
  374.         }
  375.  
  376.         boolean[] myBoolArray = new boolean[5];
  377.         for (i = 0; i < myBoolArray.length; i++){
  378.             System.out.println(myBoolArray[i]);
  379.         }
  380.  
  381.         // 8. Numbering Systems
  382.         // 8.1. Pozicionna Nepozicionna broyni systemi
  383.         //  VI
  384.         //  44 
  385.         // IV VI X XI XII
  386.         // 10 01
  387.         // base radix основа
  388.         // 0-9 основате се определя от броя на цифрите
  389.         // 8.2. Opredelqne stoynostta/tegloto na chisloto
  390.         // 234
  391.         // 2*10^2 + 3*10^1 + 4*10^0 = 2*100 + 3*10 + 4*1 = 200 + 30 + 4 = 234
  392.  
  393.         // 44(10)
  394.         // 4*10^1 + 4*10^0 = 4*10 + 4*1 = 44
  395.  
  396.         // 44(8)
  397.         // 4*8^1 + 4*8^0 = 32 + 4 = 36
  398.  
  399.         // 44(16)
  400.         // 4*16^1 + ...
  401.  
  402.         // 8.3. Preobrazuwane ot edna w druga broyni sistemi
  403.         // 8.3.1. desetichna kxm dwoichna
  404.         // from binary to decimal
  405.         // 10101010
  406.         // 1*2^7 + 0*2^6 + 1*2^5 + 0*2^4 + 1*2^3 + 0*2^2 + 1*2^1 + 0*2^0 = 128 + 32 + 8 + 2 = 170
  407.  
  408.         // 23(10) =>
  409.         // 23 : 2 = 11 | 1
  410.         // 11 : 2 = 5 | 1
  411.         // 5 : 2 = 2 | 1
  412.         // 2 : 2 = 1 | 0
  413.         //         1
  414.         // 10111(2) = 23(10)
  415.         // 1*2^4 + 1
  416.  
  417.         // from decimal to binary
  418.         // 170 / 2 = 85  0
  419.         // 85 / 2 = 42  1
  420.         // 42 / 2 = 21 0
  421.         // 21 / 2 = 10 1
  422.         // 10 / 2 = 5 0
  423.         // 5 / 2 = 2  1
  424.         // 2 / 2 = 1 0
  425.         //           1
  426.         // 10101010
  427.  
  428.         // 8.3.2. dwoichna w shestnadeseticha i osmichna 8421
  429.         // 0011 1010 1010 1111 0101 0101
  430.         // 3    A     A    F    5    5
  431.  
  432.         // 001 110 101 010 111 101 010 101
  433.         // 1    6   5   2   7   5   2   5
  434.  
  435.         // 8.3.3. floating point
  436.         // 23.45 = 10111.0101001 => 1.01110101001      4
  437.  
  438.         // 23 : 2 = 11 | 1
  439.         // 11 : 2 = 5 | 1
  440.         // 5 : 2 = 2 | 1
  441.         // 2 : 2 = 1 | 0
  442.                      1
  443.  
  444.         // .45 * 2 = 0.90 | 0
  445.         // 0.9 * 2 = 0.8 | 1
  446.  
  447.  
  448. //8.4. Praw obraten dopxlnitelen kod
  449. //8.4.1. desetichna broyna sistema
  450. //3 + 4 = 7
  451. //
  452. //        7 - 3 = 4
  453. //
  454. //
  455. //        34
  456. //
  457. //obraten kod => (10^2 - 1) - 34 = 99 - 34 = 65
  458. //        34
  459. //dopxlnitelen (10^2 ) - 34 = 66 = 65 + 1
  460. //
  461. //
  462. //        99
  463. //        -
  464. //        34
  465. //        ----------------
  466. //        65
  467. //
  468. //        9999999999999999
  469. //        -
  470. //        4343742364523476
  471. //        -----------------------
  472. //        565...
  473. //
  474. //        999
  475. //        -
  476. //        456
  477. //        ---------
  478. //        543 - obraten => dopxlnitelen 544
  479. //
  480. //        7 - 3 = 4
  481. //
  482. //        7 + 7 = 1 | 4
  483. //
  484. //        3 - 7 = -4
  485. //
  486. //        3 + 3 = 6 => -4
  487. //
  488. //        8.4.2. dwoichna broyna sistema
  489. //1111111111111
  490. //        -
  491. //        1010101111111
  492. //        -----------------
  493. //        0101010000000 => 0101010000001
  494.  
  495.         // 9. Methods
  496.         greet(); // greet("Stoyan");
  497.         int[] ages = new int[3];
  498.         // inputArray(ages);
  499.         /*
  500.         Scanner input1 = new java.util.Scanner(System.in);
  501.         for (i = 0; i < ages.length; i++) {
  502.             System.out.printf("Please enter the value of element : %d", i);
  503.             ages[i] = input.nextInt();
  504.         }
  505.         */
  506.  
  507.  
  508.         int[] fNumbers = new int[4];
  509.         // inputArray(fNumbers);
  510.         /*
  511.         Scanner fNUmbers = new java.util.Scanner(System.in);
  512.         for (i = 0; i < fNumbers.length; i++) {
  513.             System.out.printf("Please enter the value of element : %d", i);
  514.             fNumbers[i] = input.nextInt();
  515.         }
  516.         */
  517.         /*
  518.         for (i = 0; i < 10; i++) {
  519.         System.out.println(i);
  520.         }
  521.  
  522.         for (i = 20; i <=30; i++) {
  523.             System.out.println(i);
  524.         }
  525.         */
  526.  
  527.         printInterval(0, 10);
  528.         printInterval(20, 30);
  529.  
  530.         System.out.println(calculateInterest(35.0));
  531.  
  532.  
  533.         printMenu();
  534.  
  535.         // 9.1. Java doesn't have default values for the formal parameters. Use overloading instead
  536.         // Java does not support default arguments in the same way that languages like C++ or Python do. However, you can achieve similar behavior in Java using method overloading.
  537.  
  538.         // 9.2. Variable number of parameters
  539.         welcomePerson("Stoyan", "Ivan", "Petko");
  540.  
  541.  
  542.         // 10. Recursion
  543.         // 0! = 1;
  544.         // n! = (n-1)!*n
  545.  
  546.         // 3! = 1*2*3 = 6
  547.  
  548.  
  549.         int mul = 1;
  550.         for (i = 1; i <= 4; i++) {
  551.             mul *= i;
  552.         }
  553.         System.out.println("Factorial = " + mul);
  554.  
  555.         System.out.println(calculateFactorIterations(4));
  556.  
  557.         System.out.println(calculateFactorialRecursion(4));
  558.  
  559.  
  560.         // 11. Data Structures
  561.         //slow on add and remove fast on access indexes/elements
  562.         java.util.ArrayList<Integer> myArrayList = new java.util.ArrayList<Integer>();
  563.         myArrayList.add(10);
  564.         myArrayList.get(0);
  565.         System.out.println(myArrayList.get(0));
  566.  
  567.         // fast on add and remove slow on access indexes
  568.         java.util.LinkedList<Integer> myLinkedList = new java.util.LinkedList<Integer>();
  569.         myLinkedList.add(5);
  570.         myLinkedList.get(0);
  571.  
  572.  
  573.         String text = "Stoyan";
  574.         Map<String, Integer> words = new TreeMap<String, Integer>();
  575.         Scanner textScanner = new Scanner(text);
  576.         while (textScanner.hasNext()) {
  577.             String word = textScanner.next();
  578.             Integer count = words.get(word);
  579.             if (count == null) {
  580.                 count = 0;
  581.             }
  582.             words.put(word, count + 1);
  583.         }
  584.  
  585.         for (Map.Entry<String, Integer> wordEntry
  586.                 : words.entrySet()) {
  587.             System.out.printf(
  588.                     "word '%s' is seen %d times in the text%n",
  589.                     wordEntry.getKey(), wordEntry.getValue());
  590.         }
  591.     }
  592.  
  593.     // Recursion
  594.     public static int calculateFactorialRecursion(int number) {
  595.         if (number == 0) return 1;
  596.         return calculateFactorialRecursion(number -1) * number;
  597.     }
  598.  
  599.     public static int calculateFactorIterations(int number) {
  600.         int mul = 1;
  601.         for (int i = 1; i <= number; i++) {
  602.             mul *= i;
  603.         }
  604.         return mul;
  605.     }
  606.  
  607.     static void greet(String name){ // static void greet()
  608.         System.out.println("Hello " + name);
  609.     }
  610.  
  611.     public static void inputArray(int[] myArray) {
  612.         Scanner input = new java.util.Scanner(System.in);
  613.         for (int i = 0; i < myArray.length; i++) {
  614.             System.out.printf("Please enter the value of element : %d : ", i);
  615.             myArray[i] = input.nextInt();
  616.         }
  617.     }
  618.  
  619.     public static void printInterval(int from, int to){
  620.         for (int i = from; i <=to; i++) {
  621.             System.out.println(i);
  622.         }
  623.     }
  624.  
  625.     public static double calculateInterest(double amount) {
  626.         double interest = (1/4.0) * amount;
  627.         return  interest;
  628.     }
  629.  
  630.     public static double calculateCompoundInterest(double amount, double interest, int period) {
  631.         double totalAmount = amount * Math.pow((1 + interest/100), period);
  632.         return  totalAmount;
  633.     }
  634.  
  635.     public static void printMenu()
  636.     {
  637.         System.out.println("File");
  638.         System.out.println("Edit");
  639.     }
  640.  
  641.     public static boolean isPrime(int prime) {
  642.         for (int i = 2; i < prime; i++) {
  643.             if (prime % i == 0 ) {
  644.                 return false; // System.out.println("The number is NOT prime");
  645.                 // break;
  646.             }
  647.         }
  648.         return true;
  649.     }
  650.  
  651.     public static int inputNumber(int min, int max) { // String question, String question,
  652.         int age = 0;
  653.         Scanner input = new java.util.Scanner(System.in);
  654.         do {
  655.             // System.out.print("Please, enter a number between (5 to 25): ");
  656.             System.out.printf("Please, enter a number between (%1$s to %2$s): ", min, max );
  657.             age = input.nextInt();
  658.         } while( age < min || age >= max);
  659.         return age;
  660.     }
  661.  
  662.     public static void  welcomePerson(String ... people) {
  663.         for (String person : people) {
  664.             System.out.println("Welcome " + person);
  665.         }
  666.     }
  667. }
  668.  
  669. // OOP
  670. // 1. История 1967 Алан Кай
  671. // 2. Класове и обекти
  672. // 3. Елементи на класа
  673. // 4. Статични елементи на класа
  674. // 5. Inheritance - Вьзможността да се преизползват дефинираните елементите на друг клас
  675. // 6. Abstraction - Вьзможността обект от даден клас да се третира като обект от родителски клас или интерфейс
  676. // 7. Encapsulation - Вьзможността да се скриват/енкапсулират вътрешните елементи на обектите от даден клас и да се излагат само важните за потребиеля. Обикновено това са методите от интерфейсите
  677. // 8. Polymorphism - Вьзможността обектите да запазват специфичната си функционалност (методи) и да се проявяват полиморфно, въпреки прилагането на абстракция.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement