import java.util.Scanner;
public class Application{
public static void main(String ... args){
Scanner sc = new Scanner(System.in);
int answer; //our answer will be in this variable //
int number; //our number //
int firstStart = 0; //to know if we see the menu at first time //
String s;
//---------------------Single responsibility principle ----------------------------------------- | |
// 1 class - 1 duty, in other words in one class could be one public method | |
// for example - the screwdriver has something to twist. If you make it massive, then | |
// it can be used for hammering nails | |
// (though this is not very convenient), | |
--------------------------------- | |
// or another example: human Greg | |
// he opened courses for something by himself. |
//---------------------------abstraction-------------------------------- | |
// when we translit the object from real world to our class | |
// we chose only the fatures witch e need in our class | |
// for example create a class "Rectangle", and we need 4 variables for it description | |
// they are coordinates of high left corner, width and height. | |
class rect{ | |
float x,y,w,h; | |
void draw(){} |
Traditional For loop - contains three parts: the initialization, the condition, and afterthought or commonly known as increment/decrement. Classic for:
for ( int index = start_value; index < end_value; index += increment_value /*or index -= increment_value*/ )
{
// Do this code
}
Description: String is a class witch has array of char field. the length of the String is fixed!!!! (as an any array). You can think that you are changing a string, but in fact, you are creating a new string and putting old meanings with new changes in it.
- concatenation we can concatenate 2 strings using "+" or "+=" or "concat()". For example:
String s;
Queue - is very usefull structure, it designed for holding elements prior to processing. In this structure you can add elements in the end point but it can be removed in the peek of queue. Order elements in a FIFO (first-in-first-out) manner.
there are metods that throws exception or return some value;
- add(e) - Inserts the specified element into this queue if it is possible.Returning true upon success and throwing an IllegalStateException if no space is currently available. (also can throw ClassCastException, NullPointerException, IllegalArgumentException).
- offer(e) - insert element in queque if possible, otherwise returning false. But also can throws exception (ClassCastException, NullPointerException, IllegalArgumentException).
- remove() - methods remove and return the head of the queue. If queque is empty throws an NoSuchElementException exception.
- poll() - methods remove and return the head of the queue. If queque is empty returns null.
This structure allows you to store data in a linear linear collection of data elements (list). The place where the elements of the ArrayList are stored is an array. As we know the length of the array does not change. so to add some element, we need to create a new larger array, then move the data from the previous array and add a new element. Similar actions will be with the removal. but it's all happening inside the ArrayList. From the outside there are quite convenient methods to work with him.
Serializable, Cloneable, Iterable, Collection, List, RandomAccess
- add(E e) - Appends the specified element to the end of this list.
This structure allows you to store data in a linear linear collection of data elements (list). Each element is merged into a cell of this list, in turn the cell contains some element, and the links to the next and the previous elements. which allows you to store data not consistently as in the array. And they can be located across different parts of the memory.
Serializable, Cloneable, Iterable, Collection, Deque, List, Queue
- add(E e) - Appends the specified element to the end of this list.
- add(int index, E element) - Inserts the specified element at the specified position in this list.
import java.util.ArrayList;
import java.util.LinkedList;
public class Main {
private static final int LIST_LENGTH = 500000;
public static void main(String[] args) {
ArrayList<Integer> arrayList = createArrayList();
- List An ordered collection (also known as a sequence).The user of this interface has precise control over where in the list each element is inserted. The user can access elements by their integer index (position in the list), and search for elements in the list.
- Deque A linear collection that supports element insertion and removal at both ends. The name deque is short for "double ended queue" and is usually pronounced "deck". Most Deque implementations place no fixed limits on the number of elements they may contain, but this interface supports capacity-restricted deques as well as those with no fixed size limit. This interface defines methods to access the elements at both ends of the deque. Methods are provided to insert, remove, and examine the element. Each of these methods exists in two forms: one throws an exception if the operatio