Jawa / Говнокод #28791 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
public class MathGame {

    public static Map<Integer, String> data = new HashMap<Integer, String>();
    public static Map<String, Integer> result = new HashMap<String, Integer>();
    String problem;
    Random random = new Random();

    public void NewProblem() {

        String sign = null;

        for (int i = 1; i < 5; i++) {

            switch (GenNumber(3)) {
                case 1:
                    sign = Sign.MINUS.get();
                    break;
                case 2:
                    sign = Sign.PLUS.get();
                    break;
                case 3:
                    sign = Sign.TIMES.get();
                    break;
                default:
                    sign = Sign.PLUS.get();
                    break;
            }

            problem = GenNumber(9) + " " + sign + " " + GenNumber(9);
            result.put(problem + " = ???", Decide(Integer.parseInt(
                    problem.split(" ")[0]), problem.split(" ")[1], Integer
                    .parseInt(problem.split(" ")[2])));
            data.put(i, problem);

        }
    }

    private int GenNumber(int s) {
        return random.nextInt(s) + 1;
    }

    private int Decide(int a, String sign, int b) {
        switch (sign) {
            case "+":
                return a + b;
            case "-":
                return a - b;
            case "*":
                return a * b;
        }
        return 0;
    }

    public enum Sign {
        PLUS("+"),
        MINUS("-"),
        TIMES("*");

        private final String sign;

        Sign(String sign) {
            this.sign = sign;
        }

        public String get() {
            return sign;
        }

    }

}

girixok149 girixok149, (Updated )

Комментарии (0)

Jawa / Говнокод #28697 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
package sample.Model;

import static sample.Main.*;
import static sample.Model.Move.countEnemy;

class EnemyBang {
    private static double here[] = {0, 0, 0, 0};

    static void create() {
        int speedOfCreate = 150;
        if (countEnemy % speedOfCreate == 0) EnemyBang.start();
        else if (countEnemy % speedOfCreate == speedOfCreate - 1) EnemyBang.finish();
        else {
            EnemyBang.move();
            EnemyBang.heroPain();
        }
    }

    private static void whereIsPlayer(){
        if (image.getY()<enemy.getY()) here[0] = enemy.getY()-image.getY(); //w
        if (image.getY()>enemy.getY()) here[1] = image.getY()-enemy.getY();//s
        if (image.getX()<enemy.getX()) here[2] = enemy.getX()-image.getX();//a
        if (image.getX()>enemy.getX()) here[3] = image.getX()-enemy.getX();//d
    }

    private static void start() {
        bang.setX(enemy.getX()+10);
        bang.setY(enemy.getY()+10);
        bang.setVisible(true);
        here[0] = 0;
        here[1] = 0;
        here[2] = 0;
        here[3] = 0;
        EnemyBang.whereIsPlayer();
    }

    private static void finish() {
        bang.setVisible(false);

    }

    private static void heroPain() {
        int pain = 40;
        Health.change(bang, pain);
            if (CollisionObjects.check(bang, image)) {
                bang.setVisible(false);
                explosive.stop();
                explosive.play();
            }
        }

    private static void move(){
        int i = 0;
        int mover = 5;
        for (double a: here) {
            if (a != 0) i++;
        }
        if (i > 1) mover /= Math.sqrt(2);
        if (here[0]!=0 && ((here[2]/here[0]<=Math.sqrt(3) && here[2]!=0)||(here[3]/here[0]<=Math.sqrt(3) && here[3]!=0)
                || (here[2]==0 && here[3]==0))) {
            bang.setY(bang.getY() - mover);
        }
        if (here[1]!=0 && ((here[2]/here[1]<=Math.sqrt(3) && here[2]!=0)||(here[3]/here[1]<=Math.sqrt(3) && here[3]!=0)
                || (here[2]==0 && here[3]==0))) {
            bang.setY(bang.getY() + mover);
        }
        if (here[2]!=0 && ((here[0]/here[2]<=Math.sqrt(3) && here[0]!=0)||(here[1]/here[2]<=Math.sqrt(3) && here[1]!=0)
                || (here[1]==0 && here[0]==0))) {
            bang.setX(bang.getX() - mover);
        }
        if (here[3]!=0 && ((here[0]/here[3]<=Math.sqrt(3) && here[0]!=0)||(here[1]/here[3]<=Math.sqrt(3) && here[1]!=0)
                || (here[1]==0 && here[0]==0))) {
            bang.setX(bang.getX() + mover);
        }
    }
}

Всем привет, это моя третья программа, друг который мне помогает учиться отправил меня на этот сайт - сказал сюда отправить, потому что хуже кода он не видел. Подскажите, что тут не так? Он просто не комментирует

Tkachenko1380 Tkachenko1380, (Updated )

Комментарии (9, +9)

Jawa / Говнокод #28658 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
Statement stmt1 = null;
        ResultSet rs1 = null;
     
        try {
            StringBuilder sb = new StringBuilder(2000);
            String sql = "";
            String ss = "";
            String ss_begin = "";
            String ss_middle = "";
            String ss_end = "";
            int xcount = 0;
            String XXX_ID = "";
            String XXX_NAME = "";


            if (c.XLANG_ID == 1) {
                sql = sql + " SELECT  99 , 'Исходные'  FROM dual union all ";
                sql = sql + " SELECT  1 , 'Непарные исходные'  FROM dual union all ";
                sql = sql + " SELECT  2 , 'Временная'            FROM dual union all ";
                sql = sql + " SELECT  3 , 'Встречные'         FROM dual ";
                //sql = sql +  " SELECT  4 , 'Непарные встречные'         FROM dual ";
            } else if (c.XLANG_ID == 2) {
                sql = sql + " SELECT  99 , 'Base BPEBs' FROM dual union all ";
                sql = sql + " SELECT  1 , 'Base BPEBs unpaired' FROM dual union all ";
                sql = sql + " SELECT  2 , 'Temporary BPEB' FROM dual union all ";
                sql = sql + " SELECT  3 , 'Generated BPEBs' FROM dual ";
                //sql = sql +  " SELECT  4 , 'Generated BPEBs unpaired' FROM dual ";
            }

            stmt1 = this.con.createStatement();
            rs1 = stmt1.executeQuery(sql);

            while (rs1.next()) {
                xcount = xcount + 1;
                XXX_ID = rs1.getString(1);
                XXX_NAME = rs1.getString(2);

                sb = sb.append("<msg>")
                        .append("<xid>").append(XXX_ID).append("</xid>")
                        .append("<xname>").append(vtb.budget.osa.tools.Tools.stringToXML(XXX_NAME)).append("</xname>")

                        .append("</msg>");
            }
            rs1.close();
            stmt1.close();

            ss_begin = ss_begin + "<xml id='XML_table1'>"
                    + "<tab1>";

            ss_end = ss_end
                    + "</tab1>"
                    + "</xml>";

            if (xcount == 0) {
                ss_middle = ss_middle + "<msg>"
                        + "<xid></xid>"
                        + "<xcode></xcode>"
                        + "<xname></xname>"
                        + "</msg>";
            } else {
                ss_middle = sb.toString();
            }


            ss = ss_begin + ss_middle + ss_end;

            ss_begin = null;
            ss_middle = null;
            ss_end = null;
            sb = null;


            return ss;

        }

yamert89 yamert89, (Updated )

Комментарии (35, +35)

Jawa / Говнокод #28600 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
import java.lang.Math;
import java.util.Random;

public class MyVector {

    public static MyVector[] generateVectors(int N) {
        MyVector[] generated_vectors = new MyVector[N];
        for (int i = 0; i < N; i++) {
            MyVector vec = new MyVector();
            generated_vectors[i] = vec;
        }
        return generated_vectors;
    }

    public MyVector(double x, double y, double z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public MyVector() {
        final Random random = new Random();
        this.x = random.nextInt();
        this.y = random.nextInt();
        this.z = random.nextInt();
    }

    public double getX() { return this.x; }
    public void setX(double newX) { this.x = newX; }

    public double getY() { return this.y; }
    public void setY(double newY) { this.y = newY; }

    public double getZ() { return this.z; }
    public void setZ(double newZ) { this.z = newZ; }

    public double getLength() {
        return Math.sqrt(Math.pow(this.x, 2) +
                         Math.pow(this.y, 2) +
                         Math.pow(this.z, 2));
    }

    public String toString() {
        StringBuilder representation = new StringBuilder();
        representation.
            append(" { ").
            append(this.x).
            append(" ; ").
            append(this.y).
            append(" ; ").
            append(this.z).
            append(" } ");
        return representation.toString();
    }

    public double scalarProduct(MyVector vec) {
        return (this.getX() * vec.getX() +
                this.getY() * vec.getY() +
                this.getZ() * vec.getZ());
    }

    public MyVector vectorProduct(MyVector vec) {
        MyVector result = new MyVector();
        result.setX(this.getY() * vec.getZ() -
                    this.getZ() * vec.getY());
        result.setY(this.getZ() * vec.getX() -
                    this.getX() * vec.getZ());
        result.setZ(this.getX() * vec.getY() -
                    this.getY() * vec.getX());
        return result;
    }

    public MyVector substract(MyVector vec) {
        MyVector result = new MyVector();
        result.setX(this.getX() - vec.getX());
        result.setY(this.getY() - vec.getY());
        result.setZ(this.getZ() - vec.getZ());
        return result;
    }

    public MyVector add(MyVector vec) {
        MyVector result = new MyVector();
        result.setX(this.getX() + vec.getX());
        result.setY(this.getY() + vec.getY());
        result.setZ(this.getZ() + vec.getZ());
        return result;
    }

    private double x;
    private double y;
    private double z;
}

Что здесь не так?

JloJle4Ka JloJle4Ka, (Updated )

Комментарии (15, +15)

Jawa / Говнокод #28592 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;
import java.util.zip.*;
import java.io.*;
 
public class CitiesPrinter {
 
    public static void main(String[] args) throws IOException {
       
        final String fileName = "/storage/emulated/0/Documents/Jvdroid/single-files/_данные_Сбер_Java_20210407090226.zip";
        try(ZipInputStream unzipping = new ZipInputStream(new FileInputStream(fileName)));
       {
         ZipEntry entry = null;
        String name = null;
        long size = 0;
        
        while((entry=unzipping.getNextEntry())!= null) {
        name = entry.getName();
        size = entry.getSize();
        System.out.println("FileName: " + name + "FileSize: " + size);
        FileOutputStream unzippedFile = new FileOutputStream("/storage/emulated/0/Documents/Jvdroid/single-files/new" + name);
                for (int c = unzipping.read(); c != -1; c = unzipping.read()) {
                    unzippedFile.write(c);
                }
                unzippedFile.flush();
                unzipping.closeEntry();
                unzippedFile.close();
        }
       }
       catch(Exception e){
        System.out.println(e.getMessage());
       }
        
        Path path = Paths.get(fileName);
        Scanner scanner = new Scanner(path);
         
        
        scanner.useDelimiter(System.getProperty("line.separator"));
        while(scanner.hasNext()){
            System.out.println("Строка: " + scanner.next());
        }
        scanner.close();
        
        scanner = new Scanner(Paths.get("/storage/emulated/0/Documents/Jvdroid/single-files/_данные_Сбер_Java_20210407090226.zip/city_ru.csv"));
        scanner.useDelimiter(System.getProperty("line.separator"));
        while(scanner.hasNext()){
            
            Employee emp = parseCSVLine(scanner.next());
            System.out.println(emp.toString());
        }
        scanner.close();
         
        
        scanner = new Scanner(System.in);
        System.out.println("Вводим первое слово: " + scanner.next());
    }

     
    private static Employee parseCSVLine(String line) {
         Scanner scanner = new Scanner(line);
         scanner.useDelimiter("\\s*,\\s*");
         String name = scanner.next();
         int age = scanner.nextInt();
         String gender = scanner.next();
         CitiesPrinter jfs = new CitiesPrinter();
         return jfs.new Employee(name, age, gender);
    }
}
 
    class Employee{
        private String name;
        private int age;
        private String gender;
         
        public Employee(String n, int a, String gen){
            this.name = n;
            this.age = a;
            this.gender = gen;
        }
         
        @Override
        public String toString(){
            return "Name=" + this.name + "::Age=" + this.age + "::Gender=" + this.gender;
        }
    }

Что не так?

sbnet sbnet, (Updated )

Комментарии (22, +22)

Jawa / Говнокод #28543 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
static private Double getHashString(String string, Integer foundation){
    Double hash = 0.0 ;
    short [] charsToInteger = getCharArray(string);
    double step = Double.MAX_VALUE / 256 - foundation;
    for (int i = 0; i < charsToInteger.length ; i++ ){
        hash += charsToInteger[i] * step;
        step = step / 2 - 1;
    }
    return hash;
}

static private short [] getCharArray(String string){
    char [] chars = string.toLowerCase().toCharArray();
    short [] bytes = new short [chars.length];
    for (int i = 0; i < chars.length; i++){
        bytes [i] = (short) (chars[i] & 0x00FF);
        //System.out.println("bytes [" + i + "] = " + bytes[i]);
    }
    return bytes;
}

Вычисление сигнатуры строки для её применения в сортировке строк в алфавитном порядке по всем символам
https://habr.com/ru/post/709406/ / https://itnan.ru/post.php?c=1&p=709406
https://github.com/Helgi-cell/HashStringAlphabetical

ISO ISO, (Updated )

Комментарии (43, +43)

Jawa / Говнокод #28400 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
public static LanguageLevel fromPythonVersion(@Nullable String pythonVersion) {
    if (pythonVersion == null) return null;

    if (pythonVersion.startsWith("2")) {
      if (pythonVersion.startsWith("2.4")) {
        return PYTHON24;
      }
      if (pythonVersion.startsWith("2.5")) {
        return PYTHON25;
      }
      if (pythonVersion.startsWith("2.6")) {
        return PYTHON26;
      }
      if (pythonVersion.startsWith("2.7")) {
        return PYTHON27;
      }
      return DEFAULT2;
    }
    if (pythonVersion.startsWith("3")) {
      if (pythonVersion.startsWith("3.0")) {
        return PYTHON30;
      }
      if (pythonVersion.startsWith("3.1.") || pythonVersion.equals("3.1")) {
        return PYTHON31;
      }
      if (pythonVersion.startsWith("3.2")) {
        return PYTHON32;
      }
      if (pythonVersion.startsWith("3.3")) {
        return PYTHON33;
      }
      if (pythonVersion.startsWith("3.4")) {
        return PYTHON34;
      }
      if (pythonVersion.startsWith("3.5")) {
        return PYTHON35;
      }
      if (pythonVersion.startsWith("3.6")) {
        return PYTHON36;
      }
      if (pythonVersion.startsWith("3.7")) {
        return PYTHON37;
      }
      if (pythonVersion.startsWith("3.8")) {
        return PYTHON38;
      }
      if (pythonVersion.startsWith("3.9")) {
        return PYTHON39;
      }
      if (pythonVersion.startsWith("3.10")) {
        return PYTHON310;
      }
      if (pythonVersion.startsWith("3.11")) {
        return PYTHON311;
      }
      return DEFAULT3;
    }
    return getDefault();
  }

https://github.com/JetBrains/intellij-community/blob/07cef3c4397f026a5f7aa26e783b0bf7dfee5ab2/python/python-psi-api/src/com/jetbrains/python/psi/LanguageLevel.java#L125

DypHuu_niBEHb DypHuu_niBEHb, (Updated )

Комментарии (9, +9)