Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

How are primitive data types stored differently than Strings? Be able to declare variables of different types. Be able to declare more than one variable

How are primitive data types stored differently than Strings?

Be able to declare variables of different types.

Be able to declare more than one variable in a line.

Be able to declare and assign a value to a variable in the same line.

**Be able to swap the contents of two memory locations.

**Write the expression that: determines the average of three ints: num1, num2, and num3

**What are the problems with determining the average of three integer values? What happens to the remainder? What can you do to more closely determine the double value that corresponds to the actual average!?

Be able to create the output statement that will do something like this:

Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Write a statement that prints the value of price in the form "X dollars and Y cents" on a line by itself. So, if the value of price was 4321, your code would print "43 dollars and 21 cents". If the value was 501 it would print "5 dollars and 1 cents". If the value was 99 your code would print "0 dollars and 99 cents".

Be able to write a short java program

Be able to print out text

Be able to print out the contents of memory locations

Given the following expression, of what type is the result?

double * double

int / int

int % int

double / int

( int) double

(double double) * (int int)

(int / int) * double

How would you store a double value into an int variable? What is this called?

Example:

int num1 = 1;

double rnum2 = 2;

Also, what would have been stored in each of these two memory locations?

// write the statement that would assign rnum2 to num1

What is performed first? (circle the part that gets done first!)

(double + double) * (int - int)

(double + double) / int

double / (double + int)

(int /int) + double

int * int + double + double * int

int * int * double * int

int * int % int

int * int / int

What if these were replaced by values? Can you compute simple examples? (Remember that if the result is a double, you must include the fractional part or the answer would be wrong!)

Which of these will result in a decimal greater than zero?

For example, given the following declarations:

int num1=1, num2=2, num3=3 iresult=0;

double rnum1=1.0, rnum2=2.0, rnum3=3.0, dresult=0.0;

What are the results of the following computations?

iresult = num1/num2;

dresult = rnum1/rnum2;

dresult = (double) num1/num2;

dresult = (double) (num1/num2);

dresult = ((double) num1) / num2;

What does the (double) do above? And, what is this called?

Increment and decrement: What are the results of the following?

int n = 2, m = 0, p=0;

m = n++;

p = ++n;

n-- ;

--n;

System.out.println("m = " + m);

System.out.println("p = " + p);

System.out.println("n = "+ n);

System.out.println("n = "+ (--n));

System.out.println("n = "+ n);

System.out.println("n = "+ (--n));

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Design a Turing machine for anb 3 n

Answered: 1 week ago