"JAVA" first time job

Source: Internet
Author: User

First, < learning summary >1.scanner class to achieve basic data input

In Java, through the scanner class to complete the 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.
The code is as follows
java Scanner in = new Scanner(System.in); int i = in.nextInt();
The input data is stored in the variable in, scanner has no restrictions on the type of data entered, but if you want to output the data, you will have to convert the stored data to output.

ImportJava.util.Scanner Public classtest{ Public Static void Main(String args[]) Scanner in=NewScanner (System.inch);intI=in.Nextint(); System. out.println("Before conversion"); System. out.println("in"); System. out.println("After conversion");! [] (https://images2018.cnblogs.com/blog/1031679/201803/1031679-20180315141345196-1218465214.png)System. out.println("I"); }    }
The random () method of the 2.Random class and the math class

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.

import java.util.Random;publicclass Demo{    publicstaticvoidmain(String args[]){        Random a=new Random();        int a1=a.nextInt();        double b=Math.random();         System.out.println("调用Random()类产生的随机数");        System.out.println(a1);        System.out.println("调用Math.random()方法产生的随机数");        System.out.println(b);    }}
3.

SOURCE program

publicclass Test {    publicstaticvoidmain(String args[]) {         double0.1;        double0.1;        double0.1;        if0.3){            System.out.println("等于0.3");        }else {            System.out.println("不等于0.3");        }    }     }

The output is not equal to 0.3 because there is an error
Correction Code:

Package javatest;import Java.math.BigDecimal;import Java.math.MathContext; Public classS1 { Public Static void Main(String args[]) {DoubleA =0.1;Doubleb =0.1;Doublec =0.1;if((A + B + c)-0.3>0) {System. out.println("equals 0.3"); }Else{System. out.println("Not equal to 0.3."); }        }         }
4 Summary

Java and C have a lot in common in logic, but they differ in syntax, but Java adds more functionality than C, and can use C to better learn Java

Second, the experiment Summary 1. Guess the price

Program Design Ideas:
Generates a random number, uses two for loops to repeat the input, uses if to judge, if equal, uses the break to jump out the loop, the output is the number of times, if not equal, outputs the correct price.
Analysis of experimental problems:
Problem: There is a problem with the defined variable
Reason: Variable types cannot be defined repeatedly
Modify: Define it once.

2. Perpetual calendar

Program Design Ideas:
Determine whether the year that the user entered is a leap year, calculate how many years from 1990, and the number of days from January 1, 1990 that the user entered, to get the day of the week that corresponds to the date, and then to calculate the number of days corresponding to the month of the month and the corresponding output.
Analysis of experimental problems:
Question: There are questions about how many cells should be vacated before the beginning of the month of the query
Reason: Do not know how to empty the appropriate number of cells and how to assign each day of the first line to the corresponding location
Solution: Create a different sort of order for the first row than the other lines, and determine the number of cells that should be empty before the beginning of the month.

3. Mutual assessment Results

Program Design ideas: The design of the array of the most value function in the average function, call the most value function, sum each element, and then sort, and then subtract the maximum value for averaging
Problem: The result of the output is a number of times
Cause: Output plus space

Third, code hosting

"JAVA" first time job

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.