美文网首页
0x 02 Java 算数运算

0x 02 Java 算数运算

作者: 树洞void | 来源:发表于2016-11-02 22:42 被阅读0次
    import java.util.Random;
    
    /**
     * Created by Kevin on 11/1/16.
     */
    public class math {
        static void prt(String s){
    
            System.out.println(s);
        }
    
        static  void pInt(String s, int i){
            prt(s + " = " + i);
        }
    
        static  void pFlt(String s, float f){
    
            prt(s + " = " + f);
        }
    
        public static void main(String[] args){
            Random rand = new Random();
            int i, j, k;
    
            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;
            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);
    
            u += v; pFlt("u += v", u);
            u -= v; pFlt("u -= v", u);
            u *= v; pFlt("u *= v", u);
            u /= v; pFlt("u /= v", u);
    
            //for loop
            System.out.println("For Loop Example:");
            for(char c = 0; c < 128; c++){
                if (c != 26)
                    System.out.println("value: " + (int)c + " character: " + c);
            }
    
            for(int o = 0;o < 100; o++){
                if (o != 74) break;
                if (o % 9 != 0) continue;
                System.out.println(o);
            }
    
            int o = 0;
    
            while (true){
                o++;
                int p = o * 27;
                if (p == 1269) break;
                if(o % 10 != 0) continue;
                System.out.println(p);
            }
        }
    }
    
    

    不写注释了,应该很容易懂

    相关文章

      网友评论

          本文标题:0x 02 Java 算数运算

          本文链接:https://www.haomeiwen.com/subject/yblbuttx.html