# 4行代码看谁能写出更简单的写法

liuhaochuan 2008-01-16 03:22:52

void foo(int a,int b,int c)
{
int k = b;
if( a == 0) goto _L2; else goto _L1
_L1:
k++;
_L2:
if(k < c) goto _L1; else goto _L3
_L3:
return;
}

void foo(int a,int b){
int k = b;
if(a==0) {
while(k<c) { k++; }
}
else
{
do{ k++; }while(k<c)
}
}

...全文
436 点赞 收藏 30

30 条回复

JavaLover00000 2008-01-17

insiku 2008-01-17

visulcer 2008-01-17

void foo(int a, int b, int c) {
int k = b;
if (a != 0) {
k++;
}
while (k < c) {
k++;
}
}

daniel_kaka 2008-01-16

int foo(int a,int b,int c){
int k = b;
for(k=(a!=0?k+1:k); k<c; k++){
}
return k;
}

hanfengthinker 2008-01-16

daniel_kaka 2008-01-16

void foo(int a,int b,int c){
for (int k=(a!=0?b+1:b); k<c; k++){
}
}

daniel_kaka 2008-01-16

public static void foo1(int a,int b,int c){
for ( int k = b; k < c; k = (a!=0?(k+1):k)){
}
}

syhan 2008-01-16

public static int foo(int a, int b, int c) {
int k = (a == 0) ? b : b + 1;
while (k < c) k++;
return k;
}

public static int foo(int a, int b, int c)
{
int k;
for(k = a == 0 ? b : b + 1; k < c; k++);
return k;
}

Dan1980 2008-01-16

int foo2(int k) {
//do something
}

int foo(int a, int b, int c) {
int k = b;
if (a!=0)
foo2(k++);
while (k<c) foo2(k++);
return k;
}

shan1119 2008-01-16

janewayne 2008-01-16
private static void foo1(int a,int b,int c){
int k = b<c?c:(a==0?b:b+1);
System.out.println(k);
}

healer_kx 2008-01-16

liuhaochuan 2008-01-16

//反编译代码如下:
int foo2(int k)
{
...do something
}

int foo(int a,int b,int c)
{
int k = b;
if( a == 0) goto _L2; else goto _L1
_L1:
foo2(k);
k++;
_L2:
if(k < c) goto _L1; else goto _L3
_L3:
return k;
}

//我手动还原后的代码如下:
int foo2(int k)
{
...do something
}

int foo(int a,int b,int c)
{
int k = b;
if(a==0)
{
while( k < c )
{
foo2(k);
k++;
}
}
else
{
do
{
foo2(k);
k++;
}while(k < c);
}
return k;
}

shan1119 2008-01-16

Slugfest 2008-01-16

shan1119 2008-01-16

liuhaochuan 2008-01-16

shan1119 2008-01-16

Java SE

6.1w+

Java 2 Standard Edition

2008-01-16 03:22