78.7k views
4 votes
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.

2 Answers

4 votes

Answer:

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

Step-by-step explanation:

The code above has been written using Java's syntax.

To print or display statements to the console, one of the methods to use is the System.out.println() method.

According to the question, the statement to output is i=value-of-i f=value-of-f which is a string of texts.

Note that value-of-i and value-of-f are already stored in variables i and f respectively. Therefore to print them as part of the string text statement, it is important to concatenate them using the "+" operator as follows:

"i = " + i + " f = " + f

If the value of i is 25 and the value of f is 12.34 then the above statement, after successful concatenation reads:

"i = 25 f = 12.34"

which can then be shown on the console using System.out.println() method as follows:

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

Hope this helps!

User Awulf
by
4.9k points
3 votes

Answer:

cout << "i = " << i << endl << "f = " << f << endl;

Step-by-step explanation:

A statement is usually a single line of code performing a specific action. In this case, you're being asked to complete the code. You already ave to values. All you have to do is display them. So in the code above, All I have done is, tell the computer the display "i = " and then to print the value stored in i.

User Xaddict
by
5.5k points