2019a

Материал из PTHSWiki
Перейти к: навигация, поиск

Содержание

Tikz

Презентация

TeX

Conspect.jpg

Где взять Java

Скачать JDK
Скачать Eclipse

Матрица смежности

ArrayList<ArrayList<Integer>> ss = new ArrayList<>();
for (int i = 0; i < v; i++) {
        ss.add(new ArrayList<Integer>());
}

Scanner sc = new Scanner(System.in);

for (int i = 0; i < v; i++) {
        String str = sc.nextLine();
        if (str.equals("") == false) {
                String[] words = str.split("\\s+");
                System.out.println(words.length);
                for (int j = 0; j < words.length; j++) {
                        ss.get(i).add(Integer.parseInt(words[j]));
                }
        }
}

Быстрое чтение чисел через пробел

BufferedReader bi = new BufferedReader(new InputStreamReader(System.in));
String line = bi.readLine();
for (String numStr: line.split("\\s+"))
      sum += Integer.parseInt(numStr);

PriorityQueue

import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Random;


public class Main {
        static class Point implements Comparable<Point> {
                int x, y;

                public int compareTo(Point o) {
//                      if (x*x+y*y < o.x*o.x+o.y*o.y) {
//                              return -1;
//                      }
//                      if (x*x+y*y > o.x*o.x+o.y*o.y) {
//                              return 1;
//                      }
//                      return 0;
                       
                        if (x-o.x != 0) {
                                return x - o.x;
                        }
                        return o.y - y;
                }
        }

        public static void main(String[] args) {
//              Point p = new Point();
//              p.x = 3;
//              p.y = 34;
               
//              PriorityQueue<Integer> pq = new PriorityQueue<>();
//             
//              pq.add(3);
//              pq.add(15);
//              pq.add(1);
//             
//              for (int i = 0; i < 3; i++) {
//                      int a = pq.poll();
//                      System.out.println(a);
//              }
               
//              PriorityQueue<Point> pq2 = new PriorityQueue<>();
//              Random r = new Random();
//              for (int i = 0; i < 10; i++) {
//                      Point p = new Point();
//                      p.x = r.nextInt(20);
//                      p.y = r.nextInt(20);
//                      pq2.add(p);
//              }
//             
//              for (int i = 0; i < 10; i++) {
//                      Point p = pq2.poll();
//                      System.out.println(p.x + " " + p.y);
//              }
               
                Point[] arr = new Point[10];
                Random r = new Random();
                for (int i = 0; i < 10; i++) {
                        arr[i] = new Point();
                        arr[i].x = r.nextInt(20);
                        arr[i].y = r.nextInt(20);
                }
                Arrays.sort(arr);
                for (int i = 0; i < 10; i++) {
                        System.out.println(arr[i].x + " " + arr[i].y);
                }
        }

}

Функции

import java.util.Scanner;


public class Main {

        public static int abs(int x) {
                int res = x;
                if (res < 0) {
                        res = -res;
                }
                return res;
        }
       
        public static int abs2(int x) {
                if (x > 0) {
                        return x;
                }
                return -x;
        }
       
        public static double sum(double a, double b) {
                return a+b;
        }

        public static double sum(double a) {
                return a;
        }
       
        public static void strange(int y) {
                y = y - 4;
                test(y);
        }
       
        public static void arrTest(int[] arr) {
                for (int i = 0; i < arr.length; i++) {
                        test(arr[i]);
                }
        }
       
        public static void test(int a) {
                System.out.println("Вах-вах, какой красивый число: " + a);
        }
       
        public static int[] arrInput() {
                Scanner sc = new Scanner(System.in);
                int N = sc.nextInt();
                int[] arr = new int[N];
                for (int i = 0; i < N; i++) {
                        arr[i] = sc.nextInt();
                }
                return arr;
        }
               
        public static void main(String[] args) {
                int x = 45;
                strange(x);
                System.out.println(x);
               
                double c = sum(4, 65);
               
                int[] arr = arrInput();
               
                arrTest(arr);
        }

}

Первая программа

// Вася Пупкин (2019а)
// 10-11-2015
// Замечательная программа для демонстрации работы
// языка Java...

public class Main {
        public static void main(String[] args) {
                int x = 2;
                double y = 5;
               
                x = 7;
                // x = 7
                x = x + 8;
                // x = 15
               
                y = x + 1;
                // y = 16
                x = 2;
                // x = 2
                // y остался равен 16
               
                if (x > 4) {
                        System.out.println("Вах, какой большой Х");
                        System.out.println("Вах, какой большой Х");
                        System.out.println("Вах, какой большой Х");
                } else {
                        System.out.println("Ути, мой маленький");
                }

                int z = x;
                if (z < 0) {
                        z = -z;
                }
               
                int d = 12;
                if (d == 0) {
                       
                }
               
                System.out.println("x=" + x);
        }
}
Личные инструменты
Пространства имён
Варианты
Действия
Навигация
Инструменты