Today April 27, 2016, Java study the next day!
Yesterday formally entered the Java Learning Class, learned the first Java course, because the previous C language Foundation, so the course is a bit fast! Yesterday studied the first part of the textbook, the first part of a total of two chapters, respectively, Java Introduction and Java basic syntax.
- The characters in Java are encoded in Unicode, the previously learned C is encoded with ASCLL, the Unicode encoding completely contains the ASCLL code, and there are many things that are not in ASCLL;
- Each decimal constant in Java defaults to a double type;
- In the transformation of data, the automatic conversion is to automatically change the data type of the small range into a large range of data types, forcing transformation is to transform a large range of data types into a small range of data types, there are two ways to convert: digital f and (float) numbers;
- In Java, there is a data type called Boolean (Boolean), and the data type of the relational expression in Java must be a Boolean type. The statement int x=1>2 is right in the C language, and the result is x=0, which is wrong in Java, because the 1>2 data type in Java is Boolean, X is Integer, and the result of the Boolean is not assigned to the integer type. NOTE: The If statement must be of type Boolean.
The second chapter concludes with several programming questions. Book P61
1. Print the number of daffodils between 100-1000.
Code:
Package COM.CQVIE.YYC;
public class Shuixianhua {
public static void Main (string[] args) {
int a,b,c,i;
for (i=100;i<1000;i++) {
a=i/100;
B=I%100/10;
c=i%10;
if (a*a*a+b*b*b+c*c*c==i)
System.out.println (i);
}
}
}
Output:
153
370
371
407
2. Through the code, complete the exchange of two integer contents.
Code:
Package COM.CQVIE.YYC;
public class Jiaohuanlianggeshu {
public static void Main (string[] args) {
TODO auto-generated Method Stub
int a,b,c;
a=100;
b=200;
C=a;a=b;b=c;
System.out.println (a);
System.out.println (b);
}
}
Output Result:
200
100
3. Determine whether a number can be divisible by 3, 5, 7.
Code:
Package COM.CQVIE.YYC;
public class PanDuanZhengChu357 {
public static void Main (string[] args) {
TODO auto-generated Method Stub
int a=105;
if (a%3==0&&a%5==0&&a%7==0)
System.out.println ("A can be divisible by 3,5,7");
}
}
Output: A can be divisible by 3,5,7
4. Use the For loop to calculate the cumulative sum of 100-200.
Code:
Package COM.CQVIE.YYC;
public class Qiu100dao200dehefor {
public static void Main (string[] args) {
TODO auto-generated Method Stub
int sum,a,t;
sum=0;
t=100;
for (a=100;a<200;a++,t++) {
Sum=sum+t;
}
SYSTEM.OUT.PRINTLN (sum);
}
}
Output results: 14950
Start studying chapter three today.
Class and Object book p66-71
Manipulating classes with objects
Code:
The first part
Package COM.CQVIE.YYC;
public class Person {
public String name;
public int age;
public void Tell () {
SYSTEM.OUT.PRINTLN ("I Call" +name+ ", this year" +age+ ");
}
}
Part II
Package COM.CQVIE.YYC;
public class Persontest {
public static void Main (string[] args) {
Person P1=new person ();
P1.name= "Zhang San";
p1.age=18;
P1.tell ();
}
}
The second part of the execution, the result: My name Zhang San, 18 years old this year
Java Learning the next day