- 1
Админ - уебок, хранивший пароли открытым текстом
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
Админ - уебок, хранивший пароли открытым текстом
Чекайте свои мыла в утечках, ебланы
−2
Удалите мой аккаунт
Удалите мой аккаунт
+1
public int hashCode() {
HashCode h = new HashCode();
h.addValue(mFirst);
h.addValue(mSecond);
return h.hashCode();
}
Наалоцируем даже там, где нужны только примитивы
https://github.com/Netflix/netflix-commons/blob/519178a/netflix-commons-util/src/main/java/com/netflix/util/Pair.java#L119-L124
0
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;
}
}
}
−1
private boolean orPredicate;
public boolean isOrPredicate() {
return orPredicate;
}
−1
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);
}
}
}
Всем привет, это моя третья программа, друг который мне помогает учиться отправил меня на этот сайт - сказал сюда отправить, потому что хуже кода он не видел. Подскажите, что тут не так? Он просто не комментирует
+1
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;
}
−4
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;
}
Что здесь не так?
−2
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;
}
}
Что не так?
+1
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