zoukankan      html  css  js  c++  java
  • 动手动脑2

    1.随机数生成器

    import javax.swing.JOptionPane;
    public class suiji {
           public static void main( String args[] )
           {
              int value;
              String output = "";
     
              for ( int i = 1; i <= 1000; i++ ) {
                 value = 1 + (int) ( Math.random() * 6 );
                 output += value + "  ";
                  
                 if ( i % 50 == 0 )
                    output += "
    ";
              }
     
              JOptionPane.showMessageDialog( null, output,
                 "20 Random Numbers from 1 to 6",
                 JOptionPane.INFORMATION_MESSAGE );
     
              System.exit( 0 );
           }
        }

    2.

         DK中有许多System.out.println()同名的重载方法,方法名都是print()。:System是java.Lang里面的一个类。

            Out是System提供的用于标准输出的流,在没有重定向的情况下,会直接打印到终端,而println这个方式实际上是prinstream类提供的功能。

    3.java方法重载:两个函数功能相同,参数类型不同。以下为代码展示:

    public class MethodOverload {
     
        public static void main(String[] args) {
            System.out.println("The square of integer 7 is " + square(7));
            System.out.println("
    The square of double 7.5 is " + square(7.5));
        }
     
        public static int square(int x) {
            return x * x;
        }
     
        public static double square(double y) {
            return y * y;
        }
    }
  • 相关阅读:
    泛型接口协变和抗变
    泛型类功能
    泛型结构
    using 关键字给类和名称空间指定别名
    sqlite创建数据库问题
    sqlite命令
    必须输入大于0的整数
    最近在看c#本质论和B站上对应这本书的视频
    Linux系统管理笔记
    创建圆形类,其中包括set,get方法
  • 原文地址:https://www.cnblogs.com/adret/p/9787572.html
Copyright © 2011-2022 走看看