Chapter 4
1.translater the following statements to equivalent statements that use extended assignment operators:
a. x*=2
b. y/=2
2.Translate teh following statements to equivalent statements that do notuse the extended assignment operators:
a. x=x+5
b. x=x*x
4.2
1.Assume that x has the value 3.6 andd y has the value 4. state the value of he variable z after the following statements:
a.2 or -2
b.4
c.64
d.2
2. Write code segments to print the following values in a terminal window:
a. import java.util.Random;
Random generator = new Random();
System.out.print(generator.nextInt(20)+1);
b. import.java.util.Random;
Random generator = new Random();
System.out.print(generator.nextDouble(10)+1);
3-1~3-5 Question & Answer
3.1
1).Vocabulary is the set of all of the words and symbols in the language, + – * /
2).The arithmetic operators for multiply and divide must not be adjacent. And left an right paranthese mus occur in matching pairs.
3).Get the sum of x and y first and mutiple by z.
4).Natural language is like the english,which we use in our live everyday. But in programming languages should use excatly system or expression to show programming languages.
3.2
1).double=8byte;int=4byte
2)Java’s syntax for manipulating primitive data types differs distinctly from the syntax for manipulating objeects.
3)a.2.34*10^1
b.4.6*10^2
4).a.322100
b.0.0556
5). String{ya}=ya, String{oh}=oh
3.2 continued
6).A variable is an item whose value can change during he execuion of a program.
7).fahrenheit and celsius
8).double payrate=36.67
9).int.a b c =4
10).int w=1.33, int e=daivd chen
11).final double kilofrom=2.2;
12). a=25 b=-3 c=15 d=2
13). a:-* cant appear together b: we need to one more parenthesized expression. c:no funtion in the parenthesize.
14). a=2.25 b=0.444444444444 .5
15). a=valid b=valid c=syntax eror
16). a=9 b=dont worry about it
17) double x;
int y;
x=…; y=(int) (x+0.5)
18). a:Java Wizard
b:”Java 4 Wizard”
c:Java
Wizard
19). string myInfo;
double name, double address, double telephone number;
name=brian chou, address=worcester, telephone=4086463181
2.1
1.What is the portable program>
The portable program is the yields programs that can be run for different types of computer and doesnt change.
2.Describe two features of Java that make it a better language than C++
Java is less error prone, more portable.
3.What is a thread? Describe how threads might be used in a program.
It is a process that can tun concurrently with other process. The book example is a single Java application might consist of two therads, one of them transfers an image from one machine to another across a network, the other one simultaneously interacts with the use.
2.2
1.What is the JVM stand for?
Java virtal machine
2.What is byte code? Describe how the JVM uses tyte code.
The kind of object code generated by a java comiler and interpreted by a Java virtual machine. Byte code is platform independent. Some JVMs translate byte code instructions into machine language when they are first encountered, so next time the instructio is encountered it is executed as fast machine code tater taht being interpreted as slow byte code.
3. What is an applet? Describe how applets are used.
A Java program that can be run on or downloaded on a Web browser. Applets range from the decorative to the practical.
2.4
1. Give a short definition of “program.”
A set of instruction that tells the machine what to do.
2.What is the effect of the message println?
A system.out object respondsto a println message by pinting a string of characters in the terminal window.
Permalink Comments Off
Hello Quiz
1.What is this platform-independent code called?
It is call cross platform
2.Which of the following is not a valid comment?
C
3.What’s the first thing you should check f you see the following error at runtime?
The first we should check is the class name different than the file name or not.
4.It is call public static void main.
5.It can be write in either order which public static or static public). Convention is to use public static.
6.The main method usually define a single parameter, name args which is array of type string.
1. What is a bit in computer terminology? How many Bits in a Byte? How many bytes in a megabyte, and a Gigabyte?
Bit is the smallest union in computer terminology. And byte is the second,megabyte is the third, gigabyte is the largest union. It shows like bit<byte<megabyte<Gigabyte. We can count quality to show their relationship:A byte is consist 8bits; A megabyte consist 1 million bytes; A gigabyte consist 1 billion bytes.
2. Name 3 Computer input devices, 2 output devices.
input: microphone, keyboard, mouse output: monitor, speaker
3.What is a computer network?
It is a collection of resources that are linked together for communication,
4.What is the difference between hardware and software?
Base on my understanding of difference between hardware and software, hardware is the physical devices that we can see or touch for that; software is the invisible stuff which like program that makes the hardware useful.
5. What is the difference between application software and system software?
Application software is the programs that can make people to accomplish task, for example Microsoft office.
system software is the software that uses to run application which is like windows.
6. What is machine language?
Machine language is the bytes in a file of numbers. It used directly by computer’s calculation.
7. Name 5 Different programming languages.
8. What is the ACM code of ethics?
9. What is binary? How would the number 5 be represented in binary? The number 200? The number 1534?
Binary is the digit which base on 2. Because cumputer can only read for 1 and 0.The number of 5 represents 101; the number of 200 represents 11001000. The number of 1534 represents 10111111110.
10. What is a character? a String? an Integer? a boolean value?
Hello world!
Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!