- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
/**
* Four state boolean.
*/
enum Bool {
/** */
FALSE,
/** */
TRUE,
/** */
READY,
/** */
DONE
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+3
/**
* Four state boolean.
*/
enum Bool {
/** */
FALSE,
/** */
TRUE,
/** */
READY,
/** */
DONE
}
+1
private Map<Iterable<ItemStack>, Predicate<ItemStack>> getSubInventories(Map<Iterable<ItemStack>, Predicate<ItemStack>> subInventories, EntityPlayer player) {
InventoryPlayer inv = player.inventory;
ItemStack heldItem = inv.getCurrentItem();
int wireless = tile.getNetwork().getSetting(NetworkSettings.NETWORK_WIRELESS);
if((wireless >> 1 & 1) == 1) {
subInventories.put(Lists.newArrayList(heldItem), NOT_EMPTY);
}
if((wireless >> 2 & 1) == 1) {
subInventories.put(inv.offHandInventory, NOT_EMPTY);
}
if((wireless >> 3 & 1) == 1) {
subInventories.put(inv.mainInventory.subList(0, 9), stack -> !stack.isEmpty() && (heldItem.isEmpty() || heldItem != stack));
}
if((wireless >> 4 & 1) == 1) {
subInventories.put(inv.armorInventory, NOT_EMPTY);
}
if((wireless >> 5 & 1) == 1) {
if(FluxNetworks.proxy.baublesLoaded) {
if(player.hasCapability(BaublesCapabilities.CAPABILITY_BAUBLES, null)){
IItemHandler handler = player.getCapability(BaublesCapabilities.CAPABILITY_BAUBLES, null);
subInventories.put(() -> new ItemHandlerIterator(handler), NOT_EMPTY);
}
}
}
return subInventories;
}
+2
public class AdvancedBoolean {
private boolean result;
private DefenitionDictionary.RESULT_CODE code;
//------------------------------------------------------------------------------
//constructors
//------------------------------------------------------------------------------
public AdvancedBoolean() {
result = true;
}
public AdvancedBoolean(boolean _result) {
result = _result;
}
public AdvancedBoolean(boolean _result, DefenitionDictionary.RESULT_CODE _code) {
result = _result;
code = _code;
}
//------------------------------------------------------------------------------
//get methods
//------------------------------------------------------------------------------
public boolean isResult() {
return result;
}
public DefenitionDictionary.RESULT_CODE getCode() {
return code;
}
//------------------------------------------------------------------------------
//set methods
//------------------------------------------------------------------------------
public void setResult(boolean _result) {
result = _result;
}
public void setCode(DefenitionDictionary.RESULT_CODE _code) {
code = _code;
}
//------------------------------------------------------------------------------
//other methods
//------------------------------------------------------------------------------
public String getLabel() {
return code.getResultLabel();
}
}
Без комментариев
+1
float sales = new Integer(getSalesCount()).floatValue();
+1
import java.util.Scanner;
public class ComputeTax {
public static void main(String[] args) {
// Create a Scanner
Scanner input = new Scanner(System.in);
// Prompt the user to enter filing status
System.out.print(
"(0-single filer, 1-married jointly or qualifying widow(er)",
+ "\n2-married separately, 3-head of household)\n" +
"Enter the filing status: ");
int status = input.nextInt();
// Prompt the user to enter taxable income
System.out.print("Enter the taxable income: ");
double income = input.nextDouble();
// Compute tax
double tax = 0;
if (status == 0) {// Compute tax for single filers
if (income <= 8350)
tax = income * 0.10;
else if (income <= 33950)
tax = 8350 * 0.10 + (income - 8350) * 0.15;
else if (income <= 82250)
tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(income - 33950) * 0.25;
else if (income <= 171550)
tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(82250 - 33950) * 0.25 + (income - 82250) * 0.28;
else if (income <= 372950)
tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 +
(income - 171550) * 0.33;
else
tax = 8350 * 0.10 + (33950 - 8350) * 0.15 +
(82250 - 33950) * 0.25 + (171550 - 82250) * 0.28 +
(372950 - 171550) * 0.33 + (income - 372950) * 0.35;
}
else if (status == 1) {
// Left as exercise
// Compute tax for married file jointly or qualifying widow(er)
}
else if (status == 2) {
// Compute tax for married separately
// Left as exercise
}
else if (status == 3) {
// Compute tax for head of household
// Left as exercise
}
else {
System.out.println("Error: invalid status");
System.exit(1);
}
// Display the result
System.out.println("Tax is " + (int)(tax * 100) / 100.0);
}
−3
import java.util.Random;
public class Main {
public static void main(String[] args) {
Galaxy g = new Galaxy(3,77,34);
g.start();
}
}
class Galaxy extends Thread {
private int min = 1;
private int max = 100;
private final int step = 5;
private final int TIME = 1000;
volatile private int a, b, c;
Galaxy(int a, int b, int c) {
this.a = a;
this.b = b;
this.c = c;
}
public void start() {
Thread t = new Thread(this, "one");
t.start();
Thread t2 = new Thread(this, "two");
t2.start();
Thread t3 = new Thread(this, "three");
t3.start();
} @Override
public void run() { while(true) { try {
Thread.sleep(new Random().nextInt(TIME));
if(currentThread().getName().equals("one")) {
if(new Random().nextInt(2) == 1 && a > 0)
a--;
else {
if (a < max)
a++;
}
int var = a;
if(b == var || (b-1) == var || (b+1) == var)
if((b+step) > max)
b-=step;
if((b-step) < min)
b+=step;
if(c == var || (c-1) == var || (c+1) == var)
if((c+step) > max)
c-=step;
if((c-step) < min)
c+=step;
}
if(currentThread().getName().equals("two")) {
if(new Random().nextInt(2) == 1 && b > 0)
b--;
else {
if(b < max)
b++;
}
int var = b;
if(a == var || (a-1) == var || (a+1) == var) {
if((a+step) > max)
a-=step;
if((a-step) <= min)
a+=step;
}
if(c == var || (c-1) == var || (c+1) == var) {
if((c+step) > max)
c-=step;
if((c-step) <= min)
c+=step;
}
}
if(currentThread().getName().equals("three")) {
if(new Random().nextInt(2) == 1 && c > 0)
c--;
else {
if(c < max)
c++;
}
int var = c;
if(a == var || (a-1) == var || (a+1) == var) {
if((a+step) > max)
a-=step;
if((a-step) <= min)
a+=step;
}
if(b == var || (b-1) == var || (b+1) == var) {
if((b+step) > max)
b-=step;
if((b-step) <= min)
b+=step;
}
}
for(int i = min; i <= max; i++) {
int p = 0;
if(i == a || i == b || i == c)
p = 1;
System.out.print(p);
}
System.out.println();
} catch (InterruptedException e) {
e.printStackTrace();
}}}}
После запуска ждал 10 минут. Но они так и не сблизились. Программа словно остерегается сближения. Как живая.
Рашан ИИ!
0
public class Main {
public static void main(String[] args) {
Runtime r = Runtime.getRuntime();
Process p = null;
long s = System.currentTimeMillis();
try {
p = r.exec("find /");
} catch(Exception e) {
System.out.println("Ой!");
}
while(p != null ? p.isAlive() : true) {
//$_$//
}
System.out.println(p.exitValue()+(System.currentTimeMillis()-s));
}
}
Это написал победитель уральского програмсофта
Рашан программерс!
+2
public void addDisplayMethodNoAttribute()
{
addHeaderMethod();
pyScript.append("def doPrint(row, columns):\n");
pyScript.append(" line=\"\"\n");
pyScript.append(" for column in columns:\n");
pyScript.append(" if(line == \"\"):\n");
pyScript.append(" line = line + str(row[column])\n");
pyScript.append(" else:\n");
pyScript.append(" if(column == \"translations\"):\n");
pyScript.append(" line = line + separator+ \"[\"\n");
pyScript.append(" buf = \"\"\n");
pyScript.append(" for item in row[column]:\n");
pyScript.append(" if(buf != \"\"):\n");
pyScript.append(" buf = buf + \", \"\n");
pyScript.append(
" buf = buf + \"[\" + str(item[\"source\"]) + \", \" + item[\"code\"] + \", \" + item[\"comment\"] + \"]\"\n");
pyScript.append(" line = line + buf + \"]\"\n");
pyScript.append(" else:\n");
pyScript.append(" line = line + separator + str(row[column])\n");
pyScript.append(" print(line)\n");
pyScript.append("\n");
pyScript.append("list = df.collect()\n");
pyScript.append("for row in list:\n");
pyScript.append(" doPrint(row, df.columns)\n");
pyScript.append("\n");
addSessionDestroy();
generatePySparkScript();
}
Мне пытались объяснить что так лучше из-за того что не все люди знают питон, и из-за этого будем генерить его в Java.
+1
public class Main {
public static void main(String[] args) {
ThreeD[] f = {new ThreeD(5, 9, 7), new FourD(1,3,8,5)};
Coords<ThreeD> c = new Coords<>(f);
showXYZ(c);
FiveD[] x = new FiveD[] {new FiveD(11,22,3,4, 123)};
Coords<FiveD> b = new Coords<>(x);
showAll(b);
FiveD[] z = new FiveD[] {new FiveD(1,2,1,6,5)};
Coords<FiveD> zz = new Coords<>(z);
}
private static void showXY(Coords<? super FourD> c) {
for(int i = 0; i < c.coords.length; i++) {
System.out.println(c.coords[i].x +" "+ c.coords[i].y+" ");
}
}
private static void showXYZ(Coords<? extends ThreeD> c) {
for(int i = 0; i < c.coords.length; i++) {
System.out.println(c.coords[i].x +" "+ c.coords[i].y+" "+c.coords[i].z+" ");
}
}
private static void showAll(Coords<? extends FiveD> c) {
for(int i = 0; i < c.coords.length; i++) {
System.out.println(c.coords[i].x +" "+ c.coords[i].y+" "+c.coords[i].z+" "+c.coords[i].t+" "+c.coords[i].m);
}
}
}
class Coords<T extends TwoD> {
T[] coords;
Coords(T[] o) {
coords = o;
}
}
class TwoD {
int x,y;
TwoD(int a, int b) {
x = a;
y = b;
}
}
class ThreeD extends TwoD {
int z;
ThreeD(int a, int b, int c) {
super(a, b);
z = c;
}
}
class FourD extends ThreeD {
int t;
FourD(int a, int b, int c, int d) {
super(a, b, c);
t = d;
}
}
class FiveD extends FourD {
int m;
FiveD(int a, int b, int c, int d, int e) {
super(a, b, c, d);
m = e;
}
}
говнецо или нет
+1
public class Uptime {
private short minute;
private byte hour;
private short day;
private short month;
private short year;
public Uptime() {
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
executorService.scheduleAtFixedRate(() -> {
minute++;
if(minute >= 61) {
hour++;
minute = 0;
if(hour >= 25) {
day++;
hour = 0;
if(day >= 31) {
month++;
day = 0;
if(month >= 13) {
year++;
month = 0;
}
}
}
}
}, 1, 1, TimeUnit.MINUTES);
}
public short getMinute() {
return minute;
}
public byte getHour() {
return hour;
}
public short getDay() {
return day;
}
public short getMonth() {
return month;
}
public short getYear() {
return year;
}
}
Код для получения аптайма приложения.