Shortcut | Description |
---|---|
Ctrl+Shift+P | command prompt |
Ctrl+Alt+P | switch project |
Ctrl+P | go to file |
Ctrl+G | go to line |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
public class Main { | |
public static void main(String[] args) { | |
int[] mas = {2, 11, 4, 144, 32, 58, 1}; | |
boolean isSorted = false; | |
while (!isSorted){ | |
isSorted = true; | |
for (int i = 0; i <mas.length-1 ; i++) { | |
if (mas[i] > mas[i+1]){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.File; | |
import java.io.FileFilter; | |
/** | |
Класс, который реализует интерфейс FileFilter и используется для поиска файлов только с тем расширением, | |
которое передано его конструктору в качестве параметра | |
MyFilter filter = new MyFilter("doc"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
public class CopyFile { | |
public static void main(String[] args) { | |
try (FileInputStream fis = new FileInputStream("a.txt"); | |
FileOutputStream fos = new FileOutputStream("acopy.txt")) { //блок try c ресурсами | |
byte[] bufer = new byte[1024]; //буфферный массив |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PrintfExample { | |
public static void main(String[] args) { | |
int a = 5; | |
String b = "five"; | |
System.out.printf("A equals %d, and B equals %s", a , b); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Random; | |
public class RandArray { | |
public static void main(String[] args) { | |
int[] array = new int[200_000_000]; | |
Random rn = new Random(); | |
for (int i = 0; i < array.length; i++) { | |
array[i] = rn.nextInt(10); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FindFactorial { | |
public static void main(String[] args) { | |
System.out.println(factorial(5)); | |
} | |
private static int factorial(int x){ | |
return (x == 1 ? 1 : x*factorial(x-1)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InetWork { | |
public static void saveToFile(String address, File folder) { | |
try { | |
URL url = new URL(address); //установка соединения | |
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); //возможность доступа | |
InputStream is = connection.getInputStream(); //поток | |
int n = address.lastIndexOf("/"); //после последнего слеша будет имя файла | |
String fileName = address.substring(n + 1); //записываем сюда имя файла | |
File file = new File(folder, fileName); //сохраняем в каталоге фолдер с именем файлНейм | |
OutputStream os = new FileOutputStream(file); |
OlderNewer