<< Chapter < Page Chapter >> Page >

Two String operands

If both operands are references to objects of type String , the plus operator creates and returns a new String object that contains the concatenated values of the two operands.

One String operand and one of another type

If one operand is a reference to an object of type String and the other operand is of some type other than String , the plus operator causes a new String object to come into existence.

This new String object is a String representation of the non-String operand (such as a value of type int ) ,

Then it concatenates the two String objects, producing another new String object, which is the concatenation of the two.

How is the new String operand representing the non-string operand created?

The manner in which it creates the new String object that represents the non-String operand varies with the actual type of the operand.

A primitive operand

The simplest case is when the non-String operand is one of the primitive types. In these cases, the capability already exists in the core programminglanguage to produce a String object that represents the value of the primitive type.

A boolean operand

For example, if the operand is of type boolean , the new String object that represents the operand will either contain the word true or the word false.

A numeric operand

If the operand is one of the numeric types, the new String object will be composed of some of the following:

  • numeric characters
  • a decimal point character
  • minus characters
  • plus character
  • other characters such as E or e

These characters will be arranged in such a way as to represent the numeric value of the operand to a human observer.

In this program ...

In this program, a numeric double value, a numeric int value, and a boolean value were concatenated with a pair of slash characters to produce a String object containing the following:

3.5/9/true

When a reference to this String object was passed as a parameter to the println method, the code in that method extracted the character string from the String object, and displayed that character string on the screen.

The toString method

If one of the operands to the plus operator is a reference to an object, the toString method is called on the reference to produce a string that represents the object. The toString method may be overridden by the author of the class from which the object was instantiated toproduce a String that faithfully represents the object.

Back to Question 7

Answer 6

C. 4 -3

Explanation 6

A rounding algorithm

The method named doIt in this program illustrates an algorithm that can be used with a numeric cast operator (int) to cause double values to be rounded to the nearest integer.

Different than truncation toward zero

Note that this is different from simply truncating to the next integer closer to zero (as was illustrated in Question 5 ) .

Back to Question 6

Answer 5

D. 3 -3

Explanation 5

Truncates toward zero

When a double value is cast to an int , the fractional part of the double value is discarded.

This produces a result that is the next integer value closer to zero.

This is true regardless of whether the double is positive or negative. This is sometimes referred to as its "truncation toward zero" behavior.

Questions & Answers

how do you get the 2/50
Abba Reply
number of sport play by 50 student construct discrete data
Aminu Reply
width of the frangebany leaves on how to write a introduction
Theresa Reply
Solve the mean of variance
Veronica Reply
Step 1: Find the mean. To find the mean, add up all the scores, then divide them by the number of scores. ... Step 2: Find each score's deviation from the mean. ... Step 3: Square each deviation from the mean. ... Step 4: Find the sum of squares. ... Step 5: Divide the sum of squares by n – 1 or N.
kenneth
what is error
Yakuba Reply
Is mistake done to something
Vutshila
Hy
anas
hy
What is the life teble
anas
hy
Jibrin
statistics is the analyzing of data
Tajudeen Reply
what is statics?
Zelalem Reply
how do you calculate mean
Gloria Reply
diveving the sum if all values
Shaynaynay
let A1,A2 and A3 events be independent,show that (A1)^c, (A2)^c and (A3)^c are independent?
Fisaye Reply
what is statistics
Akhisani Reply
data collected all over the world
Shaynaynay
construct a less than and more than table
Imad Reply
The sample of 16 students is taken. The average age in the sample was 22 years with astandard deviation of 6 years. Construct a 95% confidence interval for the age of the population.
Aschalew Reply
Bhartdarshan' is an internet-based travel agency wherein customer can see videos of the cities they plant to visit. The number of hits daily is a normally distributed random variable with a mean of 10,000 and a standard deviation of 2,400 a. what is the probability of getting more than 12,000 hits? b. what is the probability of getting fewer than 9,000 hits?
Akshay Reply
Bhartdarshan'is an internet-based travel agency wherein customer can see videos of the cities they plan to visit. The number of hits daily is a normally distributed random variable with a mean of 10,000 and a standard deviation of 2,400. a. What is the probability of getting more than 12,000 hits
Akshay
1
Bright
Sorry i want to learn more about this question
Bright
Someone help
Bright
a= 0.20233 b=0.3384
Sufiyan
a
Shaynaynay
How do I interpret level of significance?
Mohd Reply
It depends on your business problem or in Machine Learning you could use ROC- AUC cruve to decide the threshold value
Shivam
how skewness and kurtosis are used in statistics
Owen Reply
yes what is it
Taneeya
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?

Ask