- 1
- 2
- 3
- 4
- 5
- 6
public static String hello()
{
String s = "";
s += "Добро пожаловать на наш сайт.";
return s;
}
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+86
public static String hello()
{
String s = "";
s += "Добро пожаловать на наш сайт.";
return s;
}
+85
boolean ROLLBACK = new Boolean(false).booleanValue();
И это пишет тимлид (сеньор) в моей конторе
+70
import java.util.Random;
public class A {
public static void main(String args[]) {
int minimalSuccessTime = Integer.MAX_VALUE;
int maximalSuccessTime = Integer.MIN_VALUE;
for(int i = 0; i < 10000; i++) {
Random rnd = new Random();
boolean state = rnd.nextBoolean();
final byte prisonersCount = 100;
boolean prisoners[] = new boolean[prisonersCount];
byte prisonersCounted = 1;
int daysPassed = 0;
while(true) {
daysPassed++;
int tmp = rnd.nextInt(prisonersCount);
if(tmp == 0) {
if(state) {
state = false;
prisonersCounted++;
if(prisonersCounted == prisonersCount) {
break;
}
}
} else {
if(!state && !prisoners[tmp]) {
state = true;
prisoners[tmp] = true;
}
}
}
if(daysPassed < minimalSuccessTime) {
minimalSuccessTime = daysPassed;
}
if(daysPassed > maximalSuccessTime) {
maximalSuccessTime = daysPassed;
}
}
System.out.println("Minimal success time ~= " + minimalSuccessTime/365 + " years!");
System.out.println("Maximal success time ~= " + maximalSuccessTime/365 + " years!");
}
}
One hundred prisoners have been newly ushered into prison. The warden tells
them that starting tomorrow, each of them will be placed in an isolated cell,
unable to communicate amongst each other. Each day, the warden will choose
one of the prisoners uniformly at random with replacement, and place him in
a central interrogation room containing only a light bulb with a toggle switch.
The prisoner will be able to observe the current state of the light bulb. If he
wishes, he can toggle the light bulb. He also has the option of announcing that
he believes all prisoners have visited the interrogation room at some point in
time. If this announcement is true, then all prisoners are set free, but if it is
false, all prisoners are executed.
The warden leaves, and the prisoners huddle together to discuss their fate.
Can they agree on a protocol that will guarantee their freedom?
+92
public Boolean checkPermission(String login) {
if (login == null && login.trim().length() == 0)
throw new Exception("Не указан логин пользователя.");
/* ... */
}
Чудесное условие. Есть в этом Exception что-то неуловимое - его никто никогда не поймает.
+85
String methodName = (new Exception()).getStackTrace()[1].getMethodName();
Вот как надо получать имя метода. Это вам не __func__ ...
+83
try
{
nIndex = Integer.parseInt(sRowIndex.trim());
}
catch(NumberFormatException e)
{
//异常处理
nIndex = -2;
}
if(nIndex < 0) return;
Китайцы продолжают отжигать.
+74
public void removeFromBase()
throws SQLException{
for(ServiceInstance serv: getServiceInstances())
serv.removeFromBase();
for(Pay pay: pays)
pay.removeFromBase();
String query;
PreparedStatement ps = null;
Connection connection = null;
try{
connection = TIDatasource.getInstance().getConnection();
query = "DELETE FROM orders WHERE id=?";
ps = connection.prepareStatement(query);
ps.setLong(1, getId());
int res = ps.executeUpdate();
if(res != 1)
throw new SQLException("Unexpected number of orders have deleted: " + res);
}catch(SQLException sqlex){
throw new SQLException("Can't remove order from base because of error: " + sqlex);
}finally{
ps.close();
connection.close();
}
}
PRIMARY KEY(`id`)
+80
thread = new Thread() {
@Override
public void run() {
try {
while( !dataProcessor.isFinished() ) {
dataProcessor.execute();
Thread.sleep( 60 * 1000L );
}
} catch ( Throwable t ) {
logger.fatal( "Fatal error in daemon thread", t );
}
}
};
thread.run();
Вот такое оно параллельное выполнение. Задачка для догадливых.
+76
List<Record> getNewestRecords( int maxResults ) {
List<TenantIssue> allRecords = recordsDao.getAllRecords();
if ( allRecords.size() > maxResults ) {
Collections.sort( allRecords, new Comparator() {
public int compare( Record r1, Record r2 ) {
return (int) r1.getDate().getTime() - r2.getDate().getTime();
}
} );
Collections.reverse( allRecords );
List<Record> newestRecords = new ArrayList<Record>();
for ( int i = 0; i < maxResults; i++ ) {
newestRecords.add( allRecords.get( i ) );
}
} else {
return allRecords;
}
return allRecords;
}
+79
private double findVar(String vname) throws InterpreterException {
if (!Character.isLetter(vname.charAt(0))) {
handleErr(SYNTAX);
return 0.0; // ?!
}
return vars[Character.toUpperCase(vname.charAt(0))-'A'];
}