2.3

Ace your homework & exams now with Quizwiz!

Before a variable is used it must be defined declared imported evaluated assigned

2

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 stdin = new Scanner( System.in); datum = stdin.nextInt();

Write a single statement that will print the message "first is " followed by the value of first, and then a space, followed by "second = ", followed by the value of second. Print everything on one line and go to a new line after printing. Assume that first has already been declared as a double and that second has been declared as an int. Assume also that the variables have already been given values.

System.out.println("first is " + first + " second = " + second + "\n");

The exercise instructions here are LONG -- please read them all carefully. If you see an internal scrollbar to the right of these instructions, be sure to scroll down to read everything. Given an integer variable i and a floating-point variable f, that have already been given values, write a statement that writes both of their values to standard output in the following format: i=value-of-i f=value-of-f Thus, if i's value were 25 and f's value were 12.34, the output would be: i=25 f=12.34 But you don't know what i's value and f's value are. They might be 187 and 24.06. If that's what their values are, the output from your statement should be: i=187 f=24.06 On the other hand, they might be 19 and 2.001. If that's what their values are, the output from your statement should be: i=19 f=2.001 Remember: you are GIVEN i and f-- that means they are already declared and they already have values! Don't change their values by assigning or initializing them! Just print them out the way we have shown above. Just write one statement to produce the output. Remember: in your output you must be displaying both the name of the variable (like i) and its value.

System.out.println("i="+i+" f="+f) ;

Declare two double variables, one named length with a value of 3.5 and the other named width with a value of 1.55.

double length=3.5; double width=1.55;

Declare a double variable named netWeight.

double netWeight;

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

double precise=1.09388641;

Declare a variable temperature and initialize it to 98.6.

double temperature=98.6;

Declare a variable x, suitable for storing values like 3.14159 and 6.02E23.

double x;

Declare a float variable named price.

float price;

Declare an integer variable cardsInHand and initialize it to 13.

int cardsInHand=13;

Declare an integer variable named degreesCelsius.

int degreesCelsius;

Declare two integer variables named profitStartOfQuarter and cashFlowEndOfYear.

int profitStartOfQuarter; int cashFlowEndOfYear;

Declare a variable populationChange, suitable for holding numbers like -593142 and 8930522.

long populationChange;

Write a statement that reads a floating point value from standard input into temperature. Assume that temperature. has already been declared as an double variable. Assume also that stdin is a variable that references a Scanner object associated with standard input.

temperature = stdin.nextDouble();

Write a statement that reads an integer value from standard input into val. Assume that val has already been declared as an int variable. Assume also that stdin is a variable that references a Scanner object associated with standard input.

val = stdin.nextInt();

A location in memory used for storing data and given a name in a computer program is called a because the data in the location can be changed. variable identifier That's what the name is, but what is the LOCATION called.

variable


Related study sets

med surge practice exam quiz gynie problems

View Set

BYU APUSH 062 Semester 2 Unit 5 Quiz

View Set

Chapter 42 PrepU - Management of patients with musculoskeletal trauma

View Set

Chapter 7 - Government Policy and International Trade

View Set

Exam 1: APs, Escape Responses, Nervous System, Sensory Systems

View Set

Lab Safety Review Quiz - Lab Flow

View Set