0% found this document useful (0 votes)
75 views2 pages

CMSC203 Module1 WorkSheet1 Questions

The document is a worksheet for Montgomery College's CMSC 203 course, focusing on Java programming basics such as variable definitions, constants, and arithmetic operators. It includes preprogram questions and a practice exercise for writing a Java program that displays a user's typing speed. The worksheet emphasizes variable naming conventions and includes a code template for students to complete.

Uploaded by

haressh02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views2 pages

CMSC203 Module1 WorkSheet1 Questions

The document is a worksheet for Montgomery College's CMSC 203 course, focusing on Java programming basics such as variable definitions, constants, and arithmetic operators. It includes preprogram questions and a practice exercise for writing a Java program that displays a user's typing speed. The worksheet emphasizes variable naming conventions and includes a code template for students to complete.

Uploaded by

haressh02
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Montgomery College, CMSC 203

WorkSheet1
Module 1

Objectives
- Define Variables, Literals
- constants
- Variable naming convention ( http://www.oracle.com/technetwork/java/codeconventions-
135099.html)
- Arithmetic Operators
- print, println commands
- Java Comments

Preprogram Questions
1. Which of the following is a valid java variable name:
a) ?myName
b) 12Car
c) $money
d) int

2. Declare a variable of type int to hold the student grade.

3. Declare a variable to hold the constant value for interest rate of 2.5.

4. Declare a String variable to hold the name John.

5. What is the value of z after the following code is executed?


int x = 9, y = 4;
double z = x/y;

6. What is the value of z after the following code is executed?


int x = 9;
double y = 4, z = x/y;

7. What is the value of z after the following code is executed?


int x = 9;
double y = 4, z = x%y;

8. Will the following code compile:


final int X =10;
Montgomery College, CMSC 203
WorkSheet1
Module 1

X=9;
9. Complete the following code to declare two variables of type int and print their sum using the sum
variable:

int x = 4;
___ y = 7;
int sum = x __ y;
System.out.println(_____);

10. In every java program :


a. There must be at least two variables declared
b. There must be a method called “main”
c. All of the variables must be integers

Practice writing Java Program


Create a java program that does the following (Use the given template given at the end of this
worksheet as a starting point):

- Create an integer variable to hold the approximate number of words you can type in a
minute.
- Create a String variable to hold your name.
- Display a message on the Eclipse Console showing your name and the number of words you
can type in a minute. Example: “Magi can type 50 words in a minute!”
- Use arithmetic operators to calculate the number of words you can type in a day and display
the result on the console. Example: “Magi can type 72000 words in a
day!”
- Add at least 2 useful comments to your code.

Code Template

public class VariablNames {

public static void main(String[] args) {

You might also like