Java classroom hands-on brain-method

Source: Internet
Author: User

1. View JDK Document System.out.println method overloads
1println 2 public voidprintln () 3 terminates the current line is writing the line separator string. The line separator string was defined by the system property Line.separator, and was not necessarily a single newline Charac ter (' \ n '). 4 5 public void println (Booleanx) 6 Prints A Boolean and then terminate the line. This method behaves as though it invokes print (Boolean) and then println (). 7Parameters:8 X-the BooleanTo is printed 9 public void println (charx) Prints a character and then terminate the line. This method behaves as though it invokes print (char) and then println (). 12Parameters:13 X-the CharTo is printed.14 public void println (intx) Prints an integers and then terminate the line. This method behaves as though it invokes print (int) and then println (). 17parameters:18 X-the intTo is printed.19 public void println (longx) Prints a long and then terminate the line. This method behaves as though it invokes print (long) and then println (). 22Parameters:23 X-a The LongTo is printed.24 public void println (floatx) Prints a float and then terminate the line. This method behaves as though it invokes print (float) and then println (). 27Parameters:28 x-the FloatTo is printed.29 public void println (doublex) Prints a double and then terminate the line. This method behaves as though it invokes print (double) and then println (). parameters:33 x-the double to be printed.34-public void println (char[] x) P Rints an array of characters and then terminate the line. This method behaves as though it invokes print (char[]) and then println (). PNS parameters:38 X-an array of cha RS to print.39-public void println (string x), Prints a string and then terminate the line. This method behaves as though it invokes print (String) and then println (). parameters:43 X-The String to is P rinted.44 public void println (object x) Prints a object and then terminate the line. This method calls at first string.valueof (x) to get the printed object ' s String value, then behaves as though it invokes P Rint (String) and then println (). parameters:48 x-the Object to be printed.       

2, three methods to find the number of combinations
(1) Using the combination number formula

Source

1//Use the combination number formula to calculate the number of combinations with factorial 2  3 package Bokeyuan; 4  5 import java.util.Scanner; 6  7 public class Zuheshu {8  9 public     static void main (string[] args) {ten         int n,k,sum;11         Scanner scan = new Scanner (system.in); System.out.println ("Please enter the total number and number of extracts:"); n = scan.nextint (); k = scan.nextint (); 17 18 sum = Jiecheng (n)/(Jiecheng (k) * Jiecheng (n- k)), System.out.println ("from" + N + "out" + k + "Total" + sum + " Combinations " }24 25//recursive calculation n factorial of the public static int Jiecheng (int n) {if (n < 0)//n value is not valid" return 0; if (n = = 0 || n = = 1) return 1, ELSE32 return n * Jiecheng (n-1 }34) 

(2) Using Yang Hui triangle principle to recursive the combination number

Principle:

Source:

1//Using Yang Hui triangle principle recursive combination number 2  3  4 import Java.util.Scanner; 5 6 Public  class ZuHe03 {7 public     static void< c6> Main (string[] args) {8         int i,j,n,k; 9         Scanner scan = new Scanner (system.in);         12
       system.out.println ("Please enter total number and number of pulls:"); n = scan.nextint (); k = scan.nextint (); int[][] y = new int[ n + 1][n + 1];17 y[0][0] = 1; for (i = 1;i <= n;i++) {y[i][0] = y[i][i] = 1; (j = 1;j < i;j++) Y[i][j] = y[i-1][j-1] + y[i-1 }23 ("from" + N + "out" + k + "Total" + System.out.println] + "Kind of Combination" }27}              

(3) Using Yang Hui triangle principle to calculate the combined number recursively

1//calculation combination number, using Yang Hui triangle principle recursive implementation 2  3 import java.util.Scanner; 4  5 public class ZUHESHU2 {6  7 public     Stati c void Main (string[] args) {8         int n,k,sum; 9         Scanner scan = new Scanner (system.in);         System.out.println ("Please enter total number and number of pulls:"); n = scan.nextint (); k = scan.nextint (); sum = Zuhe (n, k); System.out.println ("from" + N + "out" + k + "Total" + sum + "kind of combination" }21 public static int Zuhe (int n,int  k) {if (k < 0 | | n < k) return 0, if (n = = 0 | | n = = 1) {}28 return 1 else29 return Zuhe ( N-1,K-1) + Zuhe (n-1 }31}
     

Results:

Java classroom hands-on brain-method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.