首页 > 其他 > 详细

动手动脑

时间:2018-10-14 18:32:45      阅读:115      评论:0      收藏:0      [点我收藏+]

1,

import javax.swing.JOptionPane;

public class RandomInt {
   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 % 5 == 0 )
            output += "\n";
      }

      JOptionPane.showMessageDialog( null, output,
         "20 Random Numbers from 1 to 6",
         JOptionPane.INFORMATION_MESSAGE );

      System.exit( 0 );
   }
}

 

技术分享图片

 

2,

public class MethodOverload {

	public static void main(String[] args) {
		System.out.println("The square of integer 7 is " + square(7));
		System.out.println("\nThe 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;
	}
}

  

技术分享图片

方法重载

3,

System.out.println()

  可以输出任意形式

 

动手动脑

原文:https://www.cnblogs.com/sonofdemon/p/9787017.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!