Answer:
#include <iostream>
using namespace std;
int main() {
int k;
double d;
string s;
cin >> k >> d >> s;
cout << s << " " << d << " " << k << "\n" << k << " " << d << " " << s; }
Explanation:
k is int type variable that stores integer values.
d is double type variable that stores real number.
s is string type variable that stores word.
cin statement is used to take input from user. cin takes an integer, a real number and a word from user. The user first enters an integer value, then a real number and then a small word as input.
cout statement is used to display the output on the screen. cout displays the value of k, d and s which entered by user.
First the values of k, d and s are displayed in reverse order. This means the word is displayed first, then the real number and then the integer separated again by EXACTLY one space from each other. " " used to represent a single space.
Then next line \n is used to produce a new line.
So in the next line values of k, d and s are displayed in original order (the integer , the real, and the word), separated again by EXACTLY one space from each other.
The program along with the output is attached.
Answer:
The function in Python is as follows:
def greetings(details):
details = details.split(' ')
print('Hello, '+details[0]+'!, I also enjoy '+details[2])
Explanation:
This defines the function
def greetings(details):
This splits the input string by space
details = details.split(' ')
This prints the required output
print('Hello, '+details[0]+'!, I also enjoy '+details[2])
After splitting, the string at index 0 represents the name while the string at index 2 represents the hobby
Answer:
64 K bytes = 65536 bytes
32 M bytes = 33554432 bytes
Explanation:
The question expect the number of bytes in binary instead of decimal. So this is important to understand that:
- 1K bytes = 1024 bytes (in binary)
Therefore,
- 64 Kb = 64 x 1024 = 65536 bytes
Using the similar calculation logic, we know
- 1M bytes = 1024 x 1024 = 1048576 bytes (in binary)
Therefore,
- 32 M bytes = 32 x 1048576 = 33554432 bytes
Answer:
Question 1:
int numUsers = scnr.nextInt();
Question 2:
public class OutputExample {
public static void main (String [] args) {
int numCars = 99;
Scannerscnr=new Scanner(System.in);
numCars=scnr.nextInt();
System.out.println("There are "+numCars+" cars");
return;
}
}
Question 3:
import java.util.Scanner;
public class Errors {
public static void main(String [] args) {
int userNum = 5;
System.out.println ("Predictions are hard. ");
System.out.print("Especially ");
System.out.print("about the future.");
System.out.println("Num is: "+userNum);
return;
}
}
Explanation:
In Question 1, the statement int numUsers = scnr.nextInt(); reads a new integer value from the keyboard and assigns it to the variable numUsers.
In question 2, Concatenation is used to format the print output.
In question 3, care is taken to fix each of the syntax errors (missing double quotes, semi-colon, concatenation)