代码之家  ›  专栏  ›  技术社区  ›  DarkLeafyGreen

最小化读/写操作中的代码

  •  0
  • DarkLeafyGreen  · 技术社区  · 14 年前

    我从以下代码开始:

    class Vereinfache2_edit {
    
        public static void main(String[] args) {
    
            int c1 = Integer.parseInt(args[0]);
            int c2 = Integer.parseInt(args[1]);
            int c3 = Integer.parseInt(args[2]);
    
            /* 1 */if (c2 - c1 == 0) {
                /* 2 */if (c1 != c3) {
                    c3 += c1;
                    /* 4 */System.out.println(c3);
                    /* 5 */c3 *= c2;
                    /* 6 */}
            }
    
            /* 7 */if (c1 == c3)
                /* 8 */if (c1 - c2 == 0)
                /* 9 */{
                    c3 += c1;
                    /* 10 */System.out.println(c3);
                    /* 11 */c3 *= c1;
                    /* 12 */if (c1 < c2)
                        c2 += 7;
                    /* 13 */else
                        c2 += 5;
                    /* 14 */}
    
            /* 15 */System.out.println(c1 + c2 + c3);
        }
    
    } // end of class Vereinfache2
    

    …最后我说:

    class Vereinfache2 { 
    
            public static void main(String [] args) {
    
               int c1 = Integer.parseInt(args[0]) ;
               int c2 = Integer.parseInt(args[1]) ;
               int c3 = Integer.parseInt(args[2]) ;
    
    /*  1 */       
        /*  2 */        if (c2 == c1 && c1 != c3){  
        /*  4 */              System.out.println(c3 += c2) ; 
        /*  5 */              c3 = c3 * c2 ; 
        /*  6 */        }
    /*  7 */      
        /*  8 */        if ( c2 == c1 && c1 == c3){
        /* 10 */            System.out.println(c3 *= 2) ; 
        /* 11 */            c3 = c3 * c2 ; c2 = c2 + 5 ; 
        /* 14 */        }
    
    
    /* 15 */       System.out.println( c1+c2+c3) ;     
            }          
    
    }  // end of class Vereinfache2
    

    你有没有看到其他类似死代码或可切换代码的东西?

    谢谢你的回答。我最终得到了这个工作版本:

    class Vereinfache2 { 
    
            public static void main(String [] args) {
    
               int c1 = Integer.parseInt(args[0]) ;
               int c2 = Integer.parseInt(args[1]) ;
               int c3 = Integer.parseInt(args[2]) ;
    
    /*  1 */       if(c2 == c1){
        /*  2 */        if (c1 != c3){  
                            c3 += c2;
        /*  4 */            System.out.println(c3) ;          
        /*  6 */        }else{
                            c3 *= 2;
        /* 10 */            System.out.println(c3) ; 
        /* 14 */        }
                        c3 *= c2; c2 += 5;
                   }
    
    /* 15 */       System.out.println(c1+c2+c3) ;      
            }          
    
    }  // end of class Vereinfache2
    
    4 回复  |  直到 14 年前
        1
  •  2
  •   lbedogni    14 年前

          if (c2 == c1) {
            if (c1 != c3) {
              c3 += c1;
              System.out.println(c3);
              c3 *= c2;
            } else {
              c3 += c1;
              System.out.println(c3);
              c3 *= c1;
              if (c1 < c2)
                c2 += 7;
              else
                c2 += 5;
            }
          } else if (c1 < c2)
              c2 += 7;
            else
              c2 += 5;
        }
        System.out.println(c1 + c2 + c3);
      }
    }
    

               if (c2 == c1)
                  if( c1 != c3){  
                    System.out.println(c3 += c2) ; 
                    c3 = c3 * c2 ; 
                  } else {
                    System.out.println(c3 *= 2) ; 
                    c3 = c3 * c2 ; c2 = c2 + 5 ; 
                  }
                }          
    

        2
  •  2
  •   Johnbabu Koppolu    14 年前

    public static void main(String[] args) {
    
            int c1 = Integer.parseInt(args[0]);
            int c2 = Integer.parseInt(args[1]);
            int c3 = Integer.parseInt(args[2]);
    
            if (c2 == c1) {
            int c4 = c3 + c1;
            System.out.println(c4);
            if (c1 == c3) {
                c2 += 5;
            }
            c3 = c4 * c1;
    
        }
    
            System.out.println(c1 + c2 + c3);
        }
    

        3
  •  1
  •   bancer    14 年前

    c3 = c3 * c2; c3 *= c2;

        4
  •  1
  •   Adeel Ansari    14 年前
    /*  4 */              System.out.println(c3 += c2) ; 
    

    /*  4 */              System.out.println(c3 += c1) ; 
    

    public static void main(String[] args) {
    
        int c1 = Integer.parseInt(args[0]);
        int c2 = Integer.parseInt(args[1]);
        int c3 = Integer.parseInt(args[2]);
    
        if (c2 == c1) {
            c3 += c1;
            System.out.println(c3);
            if (c1 != c3) {
                c3 *= c2;
            } else {
                c3 *= c1;
                c2 += 5;
            }
            System.out.println(c1 + c2 + c3);
        }
    }
    

    sout

    推荐文章