Java API Reference Comments
Comments
-
Right, the StringSample constructor initializes 2 String instance variables, and it then calls print on 4 different methods. A constructor is just a method that runs when an object instance is
created, so it can call other methods just like another method can. (Stylistically the constructor is often kept simple, though I didn't follow that for this example.)
-
I had 3 "red" results on the right. Couldn't understand it until I saw line 49....commented 49 out and I am left with 1 red box.. Now I still have the 1 red box and tbh I'm quite sure I did this one right.
Can you tell me what's wrong?
-
GREEN : [apple, banana, cantaloupe, date, eggplant] RED: [apple, banana, canataloupe, date, eggplant]
5th test box on the right
-
Check that you filled in each TODO correctly. You can view a correct solution here.
-
HI I ran this in eclipse and am getting the same output as here...
HashMap map;
map = new HashMap();map.put("user", "pass");
map.put("username", "password"); map.put("java", "programming"); /* * Printing a HashMap calls the toString method of the AbstractMap class * TODO Write the code to print the HashMap * Output: {username=password, java=programming, user=pass} */ System.out.println(map);
According to your Correct Output, it should print like {username=password, java=programming, user=pass}
but it simply doesn't. -
It looks like it could print the items inside the hashmap in a different order (this is because HashMaps do not preserve the order of the elements). I simplified the problem so the correct solution
does not involve printing a hashmap with more than one item in it. Sorry for the issue and thanks for letting me know!
-
I'm having trouble with this exercise - I get the correct output which is highlighted in green but the final line where it says "All Your Output" is highlighted in red. I'm assuming the problem is with the 3rd part - my code for that is as follows:
n = in.nextInt();String word = ""; for(int i=0; i<n; i++){ //fill in code to get one word of input and print "Hi word!" word = in.next(); System.out.println("Hi " + word); }
-
@Victoria, you need to print it with an exclamation point at the end.
-
Please give the answer, as i cannot find out what ive been doing wrong
-
OK, here it is.
-
my codegot it
Stanixlav
Oct 30, 3:58 AMI'm trying to wrap my head around the code lines 11-14. Line 6 is a constructor, which defines attributes of an instance of the StringSample class. (I think this language is correct...). Then there are four print commands; will those be run whenever an instances of StringSample is created? Is that all there is to it?
Finally, can any/all methods be used within a constructor?