You are on page 1of 3

Assignment J2

Assignment J2 should be completed after you have finished all the work in Unit 2. Remember that assignments may not be resubmitted so it is important to make sure you have completed all work to the best of your ability, that you have followed the assignment instructions and have used the proper procedures and steps for submitting your assignment.

Instructions
Complete the assignment as follows: Microsoft WordAnswer all questions in MS Word. Number all questions. Notepadclass ShortExample should be written in Notepad Save your Word document and your Notepad file. When you have completed the assignment, you will have one Word document and one Notepad file.

Assignment
Rewrite the following program in Notepad. Compile and run the program: class ShortExample { public static void main (String[]args) { short value = 32;//declares and initializes variable System.out.println("A short: " + value); } } After compiling and running the above code, answer the following questions: Write your answers in a Microsoft Word document. 1. What does this program output to the monitor? 2. Make the following changes to the program: 1. Change the data type for the variable named value to the byte data type. 2. Change the variable assignment from 32 to 356. 3. After you have made the changes in #1 & #2 above, recompile the program.

4. What error message do you get and why? 3. Make the following changes to the original program: 1. Change the data type from byte to the int data type. 2. Change the assignment from 356 to 356.55. 3. Recompile the program after making the above changes. 4. What error message do you get and why? Submit this ShortExample.java file as the Notepad part of your assignment submission. 4. If the assignment is left at 356.55, there are two data types that could be used to declare the variable. 1. Which two types could be used? 2. Write the correct assignment statement using each of the two data types you have identified in #1. 3. Which of the two types you have identified is most commonly used to hold values that contain decimals? 5. Which of the following are correct literals for floating-point numbers? 1. 12.3 2. 12.3e + 2 3. 23.4e 2 4. -334.4 5. 20 6. 39F 7. 40D 6. (a) The following are numeric, primitive data types: byte, short, int, long, float and double. State the largest literal and smallest literal that can be used for each type. Use the Internet and/or the Sun Microsystem Inc. website to find your answers. (b) Which of these data types requires the least amount of memory?

7. Which of the following are correct literals for char data type? You may need to use the Internet to identify #2 and #3. 1. I 2. \u345dE 3. \u3fFa 4. \b 5. \t

Submitting the Assignment


Submit your completed assignment as follows:

Please do not zip your files. Upload your Word document and your Notepad file, one at a time, to the J2 Dropbox. There should be 2 files in the Dropbox when you are finished. 1. Word document 2. Notepad file for question #3.

You might also like