"Java Technology" first Assignment--java language Foundation

Source: Internet
Author: User

Tag: Represents the instance tin Judgment array comes with a GPO Java object

(a) Learning summary
1. In Java, through the scanner class to complete console input, consult the JDK Help document, scanner class implementation of basic data input method? Can not only use text description, must write code, through specific examples to explain.

   Scanner这个类,可以很方便的从控制台读取内容,导入所需类的文件夹(包)import java.util.Scanner;拿出你要使用的工具.Scanner,实例化Scanner对象。使用键盘输入功能,注意:in为普通变量,可以随便改Scanner in=new Scanner(System.in);提示键盘输入内容。 输入正确值后按回车结束.System.out.println("请输入整数");开始利用键盘输入值in,并存贮到定义的变量中.int num=in.nextInt();根据所输入的数字进行相关的运算.(调用变量中值开始使用);System.out.println("你所输入的数字的平方数是:"+(num*num));

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 of Util is a class: Contains Nextint (), nextdouble () and other similar methods.
The random of math is just a method: Returns a double with a positive sign that is greater than or equal to 0.0 and less than 1.0.
For example, compare the random numbers produced by two methods:


Both methods can play the same role, but if many threads need to generate pseudo-random numbers at very high rates, math.random () may reduce the contention that each thread has its own pseudo-random number generator. So many applications will find the Math.random () method easier to use.

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

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.
Floating-point data has a very small error when it is being operated.
You can use the Java.math.BigDecimal class to perform numeric operations only.
As follows:

The result is:

4. The main points of this study other needs to summarize the content: individual, according to their own learning situation, record difficult to grasp or difficult to understand the content, as well as learn the content of the experience. There are still problems, you can also put forward, for students in the blog raised questions, we can actively discuss, peer education

. The summary of this study
1, run the program often appear this situation, please teacher pointing out:

2, the method of the call process is still not very skilled, always will be some problems to think too simple.
3 The use of input, random numbers and so on need to import the required classes of the package to be;
Java and C in logic have a lot in common, but the syntax is different, but Java than C to add more features, more extensive applicability, so learn C again touch Java does not have too many difficulties.
4, when using the array, be sure to pay attention to whether the array subscript will cross the issue. Try to use the system's own. Length method to represent the length.

1, look at the price of goods guessing
Program Design Ideas:
The random function is used to generate the stochastic number, enter the price to judge, and output the guessed result.
Analysis of experimental problems:
Problem: initial Java program input and output is not very skilled, in the input and output often error.
Reason: There is no good understanding of how inputs and outputs are done.
Solution: Read Reading courseware fully understand the basic format of Java programs.

2. Perpetual calendar

Program Design Ideas:
Determine whether the year the user entered is a leap year, and then calculate the number of years from 1990 and the number of days that the user entered to calculate the day of January 1, 1990, you can get the date corresponding to the week, and then calculate the corresponding week of the beginning of the month and the number of months and corresponding output.

Analysis of experimental problems:

Question: Enter the perpetual calendar monthly number 1th and the weeks are not on
Cause: A problem occurred while calling the function
Solution: Modify the program to invoke the function in the appropriate place

3. Scoring System
Program Design Ideas:
Define the method to find the minimum average value of the maximum value, and control and invoke it in the main function. The final output of the individual rating.
Analysis of experimental problems:
Problem: Double-layered loop, but only inner loop
Cause: The curly braces for the outer for loop are discarded
Solution: Add curly braces to the corresponding location
Problem: Arrays are not used to receive the maximum minimum value for each person in the score
Reason: Defining the maximum minimum value for a score can only be a one-dimensional array. Each person's score has a maximum minimum value
Solution: Use a one-dimensional array to receive the most value and the mean value

Code Cloud Commit History

"Java Technology" first Assignment--java language Foundation

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.