"Java Technology" first time job

Source: Internet
Author: User

(a) Study Summary 1. Complete console input in Java through the scanner class, consult the JDK help documentation, what is the scanner class's approach to basic data entry? Can not only use text description, must write code, through specific examples to explain. To introduce the package import Java.util.Scanner, use a different next method to convert the resulting token to a different type of value. When the program executes to these next methods, it will cause a blockage, waiting for the user to enter data in the command line to confirm

import java.util.Scanner;public class Cdd {public static void main(String[] args) {    Scanner input=new Scanner(System.in);    System.out.print("请输入一个数:");    int a=input.nextInt();    System.out.println("输入的数为:"+a);}}

The random () method of the 2.Random class and the math class can produce a stochastic number, what is the difference between these two ways, and what are the characteristics of each? Consult the JDK Help documentation for an example. The random () method is a Java.lang.Math method that returns a double value that is greater than or equal to 0.0 and less than 1.0, and the random class is a class (Java.util.Random) that contains many methods.

3. What is the result of running the following procedure? Check the information and analyze why.

public class Test {    public static void main(String args[]) {         double a = 0.1;        double b = 0.1;        double c = 0.1;        if((a + b + c) == 0.3){            System.out.println("等于0.3");        }else {            System.out.println("不等于0.3");        }    }     }

In order to deal with the loss of precision, you can use the Java.math.BigDecimal class, consult the JDK help document or the textbook p378 to modify the above procedure. After improvement

import org.omg.CORBA.PUBLIC_MEMBER;public class Cdd {    public static void main(String args[]) {         double a = 0.1;        double b = 0.1;        double c = 0.1;        if(add( a, b, c ) == 0.3){            System.out.println("等于0.3");        }else {            System.out.println("不等于0.3");        }    }         public static double add( double d1, double d2, double d3 ) {    BigDecimal b1 = new BigDecimal( Double.toString(d1) );    BigDecimal b2 = new BigDecimal( Double.toString(d2) );    BigDecimal b3 = new BigDecimal( Double.toString(d3) );    return b1.add( b2 ).add( b3 ).doubleValue();    }}

Many of the 4.java are similar to C, but the use of data-to-method in Java is more flexible and convenient than C.

(ii) Experimental summary 1. Look at the commodity guessing price procedure design idea: by assigning an int variable random number as the commodity price, using the circular statement to make multiple guesses on the commodity price, using the break statement to jump out of the loop; 2. Perpetual Calendar Procedure Design ideas: Judging leap years, judging how many days of the input year and 1900, Leap, February Common year is 28 days, using the number of days%7+1, you can determine the current month of 1th is the number of weeks, and then you can print the current year of the current month of the calendar ; 3. Scoring System Program design ideas: Create a two-dimensional array to save the player's score, using the two-cycle and random number to give the player a score, to find out the maximum and minimum value of each player's scores, assign a value of 0, to find that the average tick except 8 is the average player, then sequential output can be;

(c) Code hosting the Cloud commit history

"Java Technology" first time job

Related Article

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.