Java Chapter 2

Your page rank:

Total word count: 529
Pages: 2

Calculate the Price

- -
275 words
Looking for Expert Opinion?
Let us have a look at your work and suggest how to improve it!
Get a Consultant

Rearrange the following code so that it forms a correct program that prints out the letter Q:

public class Q { public static void main(String[] a) { System.out.println("Q"); } }

Write a statement that prints Hello, world to the screen.

System.out.println("Hello, world");

Suppose your name was Alan Turing. Write a statement that would print your last name , followed by a comma, followed by a space and your first name .

System.out.println("Turing, Alan");

Before a variable is used it must be

declared

Which is the best identifier for a variable to represent the amount of money your boss pays you each month?

monthlyPay

Declare an integer variable named degreesCelsius.

int degreesCelsius; // Declare an int variable named degreesCelsius.

Given an integer variable drivingAge that has already been declared , write a statement that assigns the value 17 to drivingAge.

drivingAge = 17;

Two variables , num and cost have been declared and given values : num is an integer and cost is a double . Write a single statement that outputs num and cost to standard output . Print both values (num first, then cost), separated by a space on a single line that is terminated with a newline character . Do not output any thing else.

System.out.println(num + " " + cost + "\n");

Declare a short variable named patientsAge.

short patientsAge;

Declare a float variable named price.

float price;

Declare a variable isACustomer suitable for representing a true or false value .

boolean isACustomer;

Declare a character variable named c.

char c;

Declare and initialize the following variables :

monthOfYear, initialized to the value 11
companyRevenue, initialized to the value 5666777
firstClassTicketPrice, initialized to the value 6000
totalPopulation, initialized to the value 1222333

int monthOfYear = 11; int companyRevenue = 5666777; int firstClassTicketPrice = 6000; int totalPopulation = 1222333;

Declare an integer variable cardsInHand and initialize it to 13.

int cardsInHand = 13;

Declare a variable precise and initialize it to the value 1.09388641.

double precise = 1.09388641;

Given the variables fullAdmissionPrice and discountAmount (already declared and assigned values ), write an expression corresponding to the price of a discount admission.

fullAdmissionPrice – discountAmount

Write an expression that computes the average of the values 12 and 40.

(12+40) / 2

Given two integer variables matricAge and gradAge, write a statement that gives gradAge a value that is 4 more than the value of matricAge.

gradAge = matricAge + 4;

Given an integer variable bridgePlayers, write a statement that increases the value of that variable by 4.

bridgePlayers += 4;

Calculate the average (as a double ) of the values contained in the integer variables num1, num2, num3 and assign that average to the double variable avg.

Assume the variables num1, num2, and num3 have been declared and assigned values , and the variable avg declared .

avg= (double)(num1+num2+num3)/3;

Given an int variable datum that has already been declared , write a few statements that read an integer value from standard input into this variable .

Scanner input = new Scanner(System.in); datum = input.nextInt();

Declare an integer constant , MONTHS_IN_YEAR, whose value is 12.

final int MONTHS_IN_YEAR = 12;

Declare a constant MONTHS_IN_DECADE, whose value is the value of the constant MONTHS_IN_YEAR (already declared ) multiplied by 10.

final int MONTHS_IN_DECADE = MONTHS_IN_YEAR * 10 ;

Declare a variable hasPassedTest, and initialize it to true .

boolean hasPassedTest = true;

Share This
Flashcard

More flashcards like this

NCLEX 10000 Integumentary Disorders

When assessing a client with partial-thickness burns over 60% of the body, which finding should the nurse report immediately? a) ...

Read more

NCLEX 300-NEURO

A client with amyotrophic lateral sclerosis (ALS) tells the nurse, "Sometimes I feel so frustrated. I can’t do anything without ...

Read more

NASM Flashcards

Which of the following is the process of getting oxygen from the environment to the tissues of the body? Diffusion ...

Read more

Unfinished tasks keep piling up?

Let us complete them for you. Quickly and professionally.

Check Price

Successful message
sending