Question

Declare  a variable   hasPassedTest , and initialize  it to true .  


Declare  a variable   hasPassedTest , and initialize  it to true .  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

boolean hasPassedTest = true;

Add a comment
Answer #2
(resolve 'meaning)
nil

(def meaning 42)
#'user/meaning

(resolve 'meaning)
#'user/meaning

or you can boolean check it, if you need true/false:

(boolean (resolve 'meaning))
true
Add a comment
Answer #3

Java is a strongly typed programming language. This means that every variable must have a data type associated with it. For example, a variable could be declared to use one of the eight tprimitive data types: byte, short, int, long, float, double, char or boolean.

A good analogy for a variable is to think of a bucket. We can fill it to a certain level, we can replace what's inside it, and sometimes we can add or take something away from it. When we declare a variable to use a data type it's like putting a label on the bucket that says what it can be filled with. Let's say the label for the bucket is "Sand". Once the label is attached, we can only ever add or remove sand from the bucket. Anytime we try and put anything else into it, we will get stopped by the bucket police. In Java, you can think of the compiler as the bucket police. It ensures that programmers declare and use variables properly.

To declare a variable in Java, all that is needed is the data type followed by the variable name:

int numberOfDays;

In the above example, a variable called "numberOfDays" has been declared with a data type of int. Notice how the line ends with a semi-colon. The semi-colon tells the Java compiler that the declaration is complete.

Now that it has been declared, numberOfDays can only ever hold values that match the definition of the data type (i.e., for an int data type the value can only be a whole number between -2,147,483,648 to 2,147,483,647).

Declaring variables for other data types is exactly the same:

byte nextInStream;

short hour;

long totalNumberOfStars;

float reactionTime;

double itemPrice;

Initializing Variables

Before a variable can be used it must be given an initial value. This is called initializing the variable. If we try to use a variable without first giving it a value:

int numberOfDays;

//try and add 10 to the value of numberOfDays

numberOfDays = numberOfDays + 10;

the compiler will throw an error:

variable numberOfDays might not have been initialized

To initialize a variable we use an assignment statement. An assignment statement follows the same pattern as an equation in mathematics (e.g., 2 + 2 = 4). There is a left side of the equation, a right side and an equals sign (i.e., "=") in the middle. To give a variable a value, the left side is the name of the variable and the right side is the value:

int numberOfDays;

numberOfDays = 7;

In the above example, numberOfDays has been declared with a data type of int and has been giving an initial value of 7. We can now add ten to the value of numberOfDays because it has been initialized:

int numberOfDays;

numberOfDays = 7;

numberOfDays = numberOfDays + 10;

System.out.println(numberOfDays);

Typically, the initializing of a variable is done at the same time as its declaration:

//declare the variable and give it a value all in one statement

int numberOfDays = 7;

Add a comment
Know the answer?
Add Answer to:
Declare  a variable   hasPassedTest , and initialize  it to true .  
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT