20145306 study Number "Java Program design" 2nd week study Summary textbook Learning content Summary
The basic types in Java can be divided into integers, floating-point numbers, character types, Booleans, and bytes. Integers can be subdivided into short type (two bytes), int (four bytes), lang Type (eight bytes), float can be divided into float (four bytes) and double (eight bytes), char type is used to store character symbols, each character is two characters. A byte length is one byte and can represent an integer from 128 to 127. A Boolean can represent true and false two states. single-line annotations;/,/multiline annotations. Use keywords such as short,int,lang,byte,float,double,char,boolean to declare variables. Variables must be initialized before they are used. The operator provides the arithmetic function in program language Four, +,-,*,/, also called% as the modulo operator. In comparison, the conditional operator:<,>,>=,<=,!=,==; The result of the operation with a Boolean type, conditional operator condition? Set up return value: Failed return value. Logical operation: And: &&, or | | |, on the contrary! Bitwise arithmetic: There are and,or,not,xor in the design of the characters, and the complement operation, the corresponding operator in Java has the &,|,^,~; bit operation to die bitwise operation. Increment decrement operation: The difference between i++,i--,a=i++ and a=++i: i=i+1,a=i; A=i,i=i+1. When you write a floating-point number in a program, the default is double, and the next integer is the type length that is used by default that does not exceed int. If the expression has different types of numeric values, the operation is dominated by the longest type. Other values automatically promote the type. If the operands are all types that are not more than int, all are evaluated according to the INT type. Specify the operation: for example, +=:a+=b,a=a+b. If...else conditional type. Switch can be used to compare integers, characters, and strings, Enum. For loop if you want to use multiple statements in a description chunk, the statements can be separated by ",".
Problems in code debugging and the resolution process
Find the maximum common factor:
public class GCD {
public static void main(String[] args){ int a=1000,b=495,d; do{d=a%b; a=b;b=d; }while(a%b==0); System.out.println(b);}}
Program Run Results: 10 2 Find out all the Armstrong numbers:
public class amstl{
public static void main(String[] args){ int i=100; for(i=100;i<=999;i++) {if(((i/100)*(i/100)*(i/100)+((i-(i/100*100))/10)*((i-(i/100*100))/10)*((i-(i/100*100))/10)+(i%10)*(i%10)*(i%10))==i) System.out.printf("%d是阿姆斯特朗数",i);}}
Program Run Result: 153,370,371,407
Second week study summary