不行吧,prt方法变参是String,而你传入的s1+"="+i+s2+"="+f又不是。应该是s1+"="+String.valueOf(i)+s2+"="+String.valueOf(f)

解决方案 »

  1.   

    但是Thinking in java 中这样写的,也可以运行!原版copy下来!//: MathOps.java
    // Demonstrates the mathematical operators
    import java.util.*;public class MathOps {
      // Create a shorthand to save typing:
      static void prt(String s) {
        System.out.println(s);
      }
      // shorthand to print a string and an int:
      static void pInt(String s, int i) {
        prt(s + " = " + i);
      }
      // shorthand to print a string and a float:
      static void pFlt(String s, float f) {
        prt(s + " = " + f);
      }
      public static void main(String[] args) {
        // Create a random number generator,
        // seeds with current time by default:
        Random rand = new Random();
        int i, j, k;
        // '%' limits maximum value to 99:
        j = rand.nextInt() % 100;
        k = rand.nextInt() % 100;
        pInt("j",j);  pInt("k",k);
        i = j + k; pInt("j + k", i);
        i = j - k; pInt("j - k", i);
        i = k / j; pInt("k / j", i);
        i = k * j; pInt("k * j", i);
        i = k % j; pInt("k % j", i);
        j %= k; pInt("j %= k", j);
        // Floating-point number tests:
        float u,v,w;  // applies to doubles, too
        v = rand.nextFloat();
        w = rand.nextFloat();
        pFlt("v", v); pFlt("w", w);
        u = v + w; pFlt("v + w", u);
        u = v - w; pFlt("v - w", u);
        u = v * w; pFlt("v * w", u);
        u = v / w; pFlt("v / w", u);
        // the following also works for
        // char, byte, short, int, long,
        // and double:
        u += v; pFlt("u += v", u);
        u -= v; pFlt("u -= v", u);
        u *= v; pFlt("u *= v", u);
        u /= v; pFlt("u /= v", u);
      }
    } ///:~
    我只不过试试他的prt()中能不能输出多个变量,但是结果显示不出来,但是我觉得应该可以的!呵呵
      

  2.   

    哪里不对拉,JC里运行全通过。
    Random运行出来当然每次结果都不一样。
      

  3.   

    我不是这个意思!看一下下面我的疑问。
    //: MathOps.java
    // Demonstrates the mathematical operators
    import java.util.*;public class MathOps {
      // Create a shorthand to save typing:
      static void prt(String s) {
        System.out.println(s);
      }
      // shorthand to print a string and an int:
      static void pInt(String s, int i) {//这个函数能够传两个以上的参数吗?
        prt(s + " = " + i);  //比如我这样定义合法吗?static void pInt(String s, int i,int k)
      }
      // shorthand to print a string and a float:
      static void pFlt(String s, float f) {
        prt(s + " = " + f);
      }
      public static void main(String[] args) {
        // Create a random number generator,
        // seeds with current time by default:
        Random rand = new Random();
        int i, j, k;
        // '%' limits maximum value to 99:
        j = rand.nextInt() % 100;
        k = rand.nextInt() % 100;
        pInt("j",j);  pInt("k",k);
        i = j + k; pInt("j + k", i);
        i = j - k; pInt("j - k", i);
        i = k / j; pInt("k / j", i);
        i = k * j; pInt("k * j", i);
        i = k % j; pInt("k % j", i);
        j %= k; pInt("j %= k", j);
        // Floating-point number tests:
        float u,v,w;  // applies to doubles, too
        v = rand.nextFloat();
        w = rand.nextFloat();
        pFlt("v", v); pFlt("w", w);
        u = v + w; pFlt("v + w", u);
        u = v - w; pFlt("v - w", u);
        u = v * w; pFlt("v * w", u);
        u = v / w; pFlt("v / w", u);
        // the following also works for
        // char, byte, short, int, long,
        // and double:
        u += v; pFlt("u += v", u);
        u -= v; pFlt("u -= v", u);
        u *= v; pFlt("u *= v", u);
        u /= v; pFlt("u /= v", u);
      }
    } ///:~
      

  4.   

    看我下面这个程序有毛病吗?import java.util.*;
    public class Test{
     static void prt(String s){
    System.out.println(s);}
    static void pInt(String s1,int i,String s2,float f){
                       prt(s1+"="+i+s2+"="+f);
    }
     public static void main(String args[]){
    Random rand=new Random();
    int i=rand.nextInt()%100;
             float f=rand.nextFloat();
    pInt("i",i,"f",f);
    }
            }
        
      

  5.   

    wcj1981(宇宙之神) 
    你从sohu过来啦,还记得我吗?呵呵