Я делаю доклад в университете и часть моей темы - это история Java-апплетов. Проблема в том, что полноценно я как-то не могу ее найти. На том же Хабре есть лишь история самой Java, но не про апплеты, про них как-то супер мало.
то есть ,если я пишу в консоль букву А ,то мне должны вывестись все таски с именем начинающиеся на А.Это не сортировка.
int a = 42;
int b = 55;
System.out.println(a < b);
не могу найти ошибку
int y = n/2;
...
&& (y > (n-1))
всегда false.Программа в каждом случае выдаёт 0.
int deadEnds = 0;
...
100*deadEnds/trials == 0
0/n = 0Оператор == проверяет ссылки, а не значения
В Java сравнение строк equals проверяет исходное содержимое строки. Он возвращает true, если параметр — это объект String, который представляет собой ту же строку символов, что и объект...
С чем это связано?
Each ArrayList instance has a capacity. The capacity is the size of the array used to store the elements in the list. It is always at least as large as the list size. As elements are added to an ArrayList, its capacity grows automatically. The details of the growth policy are not specified beyond the fact that adding an element has constant amortized time cost.
An application can increase the capacity of an ArrayList instance before adding a large number of elements using the ensureCapacity operation. This may reduce the amount of incremental reallocation.
public ListIterator<E> listIterator(int index) {
checkPositionIndex(index);
return new ListItr(index);
}
// ...
private class ListItr implements ListIterator<E> {
private Node<E> lastReturned = null;
private Node<E> next;
private int nextIndex;
private int expectedModCount = modCount;
ListItr(int index) {
// assert isPositionIndex(index);
next = (index == size) ? null : node(index);
nextIndex = index;
}
public boolean hasNext() {
return nextIndex < size;
}
public E next() {
checkForComodification();
if (!hasNext())
throw new NoSuchElementException();
lastReturned = next;
next = next.next;
nextIndex++;
return lastReturned.item;
}
private class Itr implements Iterator<E> {
int cursor; // index of next element to return
int lastRet = -1; // index of last element returned; -1 if no such
int expectedModCount = modCount;
public boolean hasNext() {
return cursor != size;
}
@SuppressWarnings("unchecked")
public E next() {
checkForComodification();
int i = cursor;
if (i >= size)
throw new NoSuchElementException();
Object[] elementData = ArrayList.this.elementData;
if (i >= elementData.length)
throw new ConcurrentModificationException();
cursor = i + 1;
return (E) elementData[lastRet = i];
}
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
class CircleCanvas extends Canvas
{
public void paint(Graphics g)
{
Dimension d = this.getSize();
int diam = Math.min(d.width - 1, d.height - 1) - 60;
g.drawOval(20, 20, diam, diam);
}
}
class MyFrame extends Frame
{
public MyFrame()
{
super("Painting");
setBackground(Color.gray); // GRAY а не GREY
setLayout(new GridLayout(3, 3));
add(new CircleCanvas());
setSize(500, 400);
setVisible(true);
// обработчик событий
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
}
}
public class RunGn
{
public static void main(String[] u)
{
Frame f = new MyFrame();
}
}
Что нужно знать java back-end junior разработчику помимо языка
int[] removeNthElm(int[] array, int nElement)
{
// перемещаем нужный элемент в конец
for(int i = nElement - 1; i < array.length - 1; ++i)
{
// типа swap
int a = array[i];
array[i] = array[i + 1];
array[i + 1] = a;
}
return shorten(array);
}
void draw()
{
int[] a = {1, 2, 3, 4, 5};
a = removeNthElm(a, 1);
printArray(a);
exit();
}
OUT:
[0] 2
[1] 3
[2] 4
[3] 5
The shorten() function decreases an array by one element by removing the last element and returns the shortened array:
Нигде не могу найти примера алг-ма "Модульная инверсия", для того, чтобы разобраться самостоятельно и понять данный алгоритм.
public static void main(String[] args)
{
Scanner io = new Scanner(System.in);
int max = 0;
int cur = 0;
int step = 0;
while(step++ < 4 && io.hasNextInt())
{
cur = io.nextInt();
if(cur > max) max = cur;
}
System.out.printf("Max: %d", max);
}