Java Programming Basics Review Notes Unit II

Source: Internet
Author: User
Tags float double pow

1
Raw datatype (primitive data type) = = Base type (fundamental type)
byte short int long float double char Boolean
Reference type Reference type
2
System.in System.out
Java.util.Scanner
Scanner input = new Scanner (system.in);
Nextbyte ()
Nextshort ()
Nextint ()
Nextlong ()
Nextfloat ()
Nextdouble ()
Next ()
Nextline ()
3
Identifier
The identifier must be an alphanumeric underscore and a sequence of characters, which, in practice, is used only in the source code generated automatically by the machine
Cannot start with a number,
Cannot be a reserved word,
It can't be true,false,null.
can be any length
Case sensitive
4
Named constant named constant
Final datatype constantname = value;
You must declare and assign values in the same statement
5
Overflow:int value = 2147483647 + 1; int value2 =-2147483648-1;
Java does not report warnings or errors about overflow
Underflow:java is approximately 0.
6
%: The remainder is negative only if the divisor is a negative number
7
Numerical Direct quantity literal
Integral type Direct Quantity
Long plus L or l
Floating-point Direct volume
Double plus d or D
Float F or F
Scientific counting method E or e 12.3e+2 = = 12.3e2
8
Long System.currenttimemillis () returns the number of milliseconds GMT 1,1,1970 0:00 (Unix timestamp) to the current time
9
Introduction to Assignment operators
10
Numeric type conversions
Widening type widening a type
Narrowing type narrowing a type
11
Math.pow (Base,times)
12
Encoding
Encoding scheme
Char 16
Integral type converted to char type truncation occurs
Byte needs to be explicitly converted
Unicode
Unicode Consortium
Supplementary character
\U0000-\UFFFF, 4 16-bit binary digits must be supplied
If you do not see Chinese characters installed
13
Escape character escape character
14
Do not use Nextline () after Nextbyte (), Nextint (), etc.
15
Java Documentation Comments
/** Start */End
Binary operators should have one space on each side
16
The style of the BLOCK:
Second row Next-line
Line End End-of-line
17
Java cannot detect from compilation errors except 0
Debugging Tools
18
Javax.swing.JOptionPane.showInputDialog (Null,title,message,ircon);
19
int Intvalue=integer.parseint (intstring);
The runtime error will appear if the input is not a value or if you clicked Cancel
Both the integer class and the double class are included in the Java.lang package
20
' A '-' C ' =-2
Show int Value
21st
JAVA-CP Exercise8e.zip Exercise2_1
22
Java.util.Scanner

Keyword:
Algorithm
Assignment operator
Assignment statement
backslash (\)
BYTE type
Casting
Char type
constant
Data type
Debugger
Debugging
Declaration
Decrement operator
Double type
Encoding
Final
Float type
Floating-point number
Expression
Identifier
Increment operator
Incremental developing and testing
Indentation
int type
Literal
Logic error
Long type
Narrowing
operator
Overflow
Pseudocode
Primitive data type
Runtime error
Syntax error
Supplementary Unicode
Short type
Underflow
Unicode
UNIX Epoch
Variable
Widening
Whitespace


Exercises
2.1
Legal: Applet,applet,$4,apps,x,y,radius
Keyword: class,public,int
2.2
Double miles=100;
Final Double kilometers_per_mile=1.09
Double kilometers=miles*kilometers_per_mile;
System.out.println (kilometers);
109
2.3
Improves readability, prevents constant value changes, and is easy to maintain
final int size=20;
2.4
5
15
50
1
6.5
-4.5
2.5
2
-2
-1
4
0
1
2.6
Thursday
2.7
byte-128-127 8
short-32768-32767 16
int-2147483648-2147483647 32
long-9,223,372,036,854,775,808-92233720369547758807
float +-(1.4e-45-3.4028235e+38) 32
Double +-(4.9e-324-1.797 693 134 862 315 7E+308)
2.8
6
25.0/4
2.9
From the computer's point of view are correct
2.10
4/3.0/(r+34) -9* (A+BC) + (double) (3+d* (2+a))/(A+B*D)
2.11
(double) (M*R*R)
M*math.pow (r,2);
2.12
(2) (3)
2.13
12.3,12.3e+2,23.4e-2,-334.4,20,39f,40d
2.14
2:public static void
4:int k = 100;
7:and Change to +
2.15
int currentminute = (int) (System.currentmillis ()%36000000/60000*60)
2.16
Automatic conversions can occur, but the float and int,long and double operations require an explicit conversion
2.17
Truncation truncation occurred
Change
2.18
12.5
12
2.19
49
65
66
97
98
(
;
O
U
Z
@
Z
Q
R
Z
2.20
' 1 ', ' \u3ffa ', ' \b '
2.21
\\
\"
2.23
char c = ' A ';
i = (int) c;//i=67
float F = 1000.34f;
int i = (int) f;//variable repeating declaration, 1000

Double d = 1000.34;
int i = (int) d;//1000

int i = 97;
char C = (char) i;//' C '
2.24
' B '
C
-2
2.25
11
11
111
12
111
2.26
1welcome11
1welcome2
1welcome2
1welcomea1
2.27
Constant: Max_value
Class or interface: Test
Constant or method name: Read,readint
2.28
.............
2.29
Syntax error: Syntax not canonical, compiler error
Run Error: Error reported during operation, affecting program uptime
Logic Error: Programming content error, instruction can not achieve due effect
2.30
Joptionpane is in the javax.swing package, not the default import
The math class is in the Java.lang package, and the default import
2.31
int i = integer.parseint (Javax.swing.JOptionPane.showInputDialog (NULL, "Please enter an integer"));

Programming Exercises:
2.9

public class Exercise2-9 {

public static void Main (string[] args) {
//TODO auto-generated method Stub
String money = Javax.swing.JOptionPan E.showinputdialog (NULL, "Please enter the amount of money");
int Ind=money.indexof ('. ');
String penny = money.substring (ind+1);
money=money.substring (0, Ind);
int I=integer.parseunsignedint (money,10) *100+integer.parseunsignedint (Penny);
Javax.swing.JOptionPane.showMessageDialog (NULL, "Answer" +i+ "penny", "Result", joptionpane.information_message );
}
}
2.18

public class Exercise {
public static void print (String a) {
System.out.printf ("%-10s", a);
}
public static void Main (string[] args) {
Print ("a");p rint ("B");p rint ("pow (b)"); System.out.println ();
for (int i=1;i<6;i++) {
String s = "" +i;
print (s);
s = string.valueof (i+1);
print (s);
s = "" + (int) Math.pow (i, i+1);
print (s); System.out.println ();
}
}
}
2.25
Import Java.util.Scanner;
public class Exercise {
public static void Main (string[] args) {
System.out.print ("Enter The time zone offset to GMT:");
Scanner Scanner = new Scanner (system.in);
int I=scanner.nextint ();
Long Second=system.currenttimemillis ()/1000-3600*i;
int sec = (int) (SECOND%60);
second/=60;
int min = (int) second%60;
second/=60;
int hour = (int) second%24;
System.out.print ("The current time is" +hour+ ":" +min+ ":" +sec);

}
}

Java Programming Basics Review Notes Unit II

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.