日期:2014-05-20  浏览次数:20780 次

如何使这个java代码输出结果i,j,b,c,d,f,f3,f4
public class method{
public static void main(String[] args){

}
public void method(){
int i = 1, j = 2;
float f1 = (float)0.1; float f2 = 123;
long l1 = 12345678, l2 = 888888888L;
double d1 = 2e20, d2 = 124;
byte b1 = 1, b2 = 2, b3 = 127;
j = j + 10;
i = (int)i / 10;
i = i * 10;
char c1 = 'a', c2 = (char)125;
byte b =(byte)( b1 - b2 );
char c =(char)( c1 + c2 - 1);
float f3 = (float)(f1 + f2);
float f4 =(float)( f1 + f2 * 0.1);
double d = d1 * i + j;
float f = (float)(d1 * 5 + d2);
  }
}

------解决方案--------------------
Java code

public class method {
    public static void main(String[] args) {
    System.out.println("i,j,b,c,d,f,f3,f4");
    
    }
    public  void method() {
    int i = 1, j = 2;
    float f1 = (float) 0.1;
    float f2 = 123;
    long l1 = 12345678, l2 = 888888888L;
    double d1 = 2e20, d2 = 124;
    byte b1 = 1, b2 = 2, b3 = 127;
    j = j + 10;
    i = (int) i / 10;
    i = i * 10;
    char c1 = 'a', c2 = (char) 125;
    byte b = (byte) (b1 - b2);
    char c = (char) (c1 + c2 - 1);
    float f3 = (float) (f1 + f2);
    float f4 = (float) (f1 + f2 * 0.1);
    double d = d1 * i + j;
    float f = (float) (d1 * 5 + d2);
    }
}/*
i,j,b,c,d,f,f3,f4
*/

------解决方案--------------------
Java code

public class Method{
    public static void main(String[] args){
        Method te = new Method();
        te.method();
        
    }
    public void method(){
        int i = 1, j = 2;
        float f1 = (float)0.1; float f2 = 123;
        long l1 = 12345678, l2 = 888888888L;
        double d1 = 2e20, d2 = 124;
        byte b1 = 1, b2 = 2, b3 = 127;
        j = j + 10;
        i = (int)i / 10;
        i = i * 10;
        char c1 = 'a', c2 = (char)125;
        byte b =(byte)( b1 - b2 );
        char c =(char)( c1 + c2 - 1);
        float f3 = (float)(f1 + f2);
        float f4 =(float)( f1 + f2 * 0.1);
        double d = d1 * i + j;
        float f = (float)(d1 * 5 + d2);
        System.out.println("i = "+i+"   j = "+j+"   b = "+b+"   c = "+c);
        System.out.println("d = "+d+"   f = "+f+"   f3 = "+f3+"   f4 = "+f4);
        }
    }
输出:
i = 0   j = 12   b = -1   c = ?
d = 12.0   f = 1.0E21   f3 = 123.1   f4 = 12.4

------解决方案--------------------
探讨

Java code

public class Method{
public static void main(String[] args){
Method te = new Method();
te.method();

}
public void method(){
int i = 1, j = 2;
……