Skip to main content.

Assignment 1 FAQ

Assignment 1

Debugging

I am trying to concatenate the characters together and display them, but a number is getting displayed. I checked that each individual character is correct by displaying them separately.

Note: if you're reading this answer and you didn't validate your individual characters, go back and do that first.

There are a few slides that hint at the solution, but let's start by considering the following code:

      int x=1;
      int y=2;
      System.out.println(x+y);

What is the code's expected output? Why? What is the order of operations/processing that is happening?

Now, use that to interpret your code and its output.

What would you do to the above code so that the expected output is 12?

With that understanding, look at the other printing examples in this class's main method and check out if there are some slides from class that help solve this issue.

OK, I get that part, but why was it printing out 344?

Computers need to represent everything in binary. We need to convert letters (or characters in general) to numbers and then to binary. You may have heard of ASCII or Unicode to encode characters.

The Python function ord can convert a one-character string to its Unicode value. For example, in interactive mode in Python:

>>> ord('w') + ord('l') + ord('u')
344