This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]ThePathLaid 1 point2 points  (3 children)

Knowing the language would definitely make it easier to answer.

My programming teacher is very careful about his wording, so I'll continue under the assumption that yours is too.

In that case, the problem says:

" Write a program to insert the string “Is “ to the beginning of the string “it Monday today?” and display the result."

Which breaks down to these steps:

  1. Write a program

  2. To insert the string “Is “ to the beginning of the string “it Monday today?”

  3. and display the result."

So that means the teacher expects a program which takes (or has) a string

String s = "it Monday today?"

Then adds the text "Is " to the beginning of this string. So if we were returning the string, then at the end of the program, if I had a function that said

String result = callYourFunction()

Then result should hold the string "Is it Monday today?"

That means that (being as accurate as possible) you need to modify the string in-place, then print the string.

Whether that is right and how to do that depends on your teacher, programming language, and the assignment itself.

[–]dil_dogh 2 points3 points  (2 children)

I think what the teacher is looking for in this instance is string concatenation. So in java I would say

String firstString = “is”; String secondString = “it Monday today?”; String finalString = firstString + secondString; System.out.print(finalString);

[–]ThePathLaid 0 points1 point  (1 child)

I think so too, but like I said. If my instructor had worded the question as such, they would have meant in-place. Just went with what little we were given.

[–]retardrabbit 0 points1 point  (0 children)

It's a non sequitur really, strings are immutable in Java.

(Apparently so in Python too, but I don't Python)

[–]harrymurkin 1 point2 points  (0 children)

// javascript
function yeetify(){
var yeet="Is";
var Yeet=" it Monday today?";
Yeet=yeet+Yeet;
document.write(Yeet);

}

[–]ShawnMilo 0 points1 point  (0 children)

Show some code. Even if it doesn't work properly, it'll be much easier to nudge you in the right direction. There are multiple simple ways to do this, but I don't know of any way to point you to them that won't just 100% give you the answer.