Java Language Details Comments

Comments

  • Why is (1) incorrect? Can not I write :

    for(int num : array1){
    if(num%2!=0 && num<200){
    System.out.println(num);
    }
    }

  • @Lukas, there's no array to go through. And if there was, num would be set to the values in the array, since it's a for-each loop, which is probably different than 1 to 200.

  • I don't really understand fully this challenge... and I'm getting frustrated trying to do this simple task.

    Here's my code:

    String word; for(int num : words){ word+=words[num] };

    I find it really hard to write code in that little field.

  • In the first challenge, you just need to declare the 'header' for the for loop. Since it goes through a String array you'll need to declare the variable as a String.

  • Is the Raw I/O correct? If i test the code without changing it to a do...while loop, i get the same incorrect result for each input as after changing it to a do...while loop. I tested input and first is 0, second is 2, third is 4, other is 3, 5, 1.

  • @Peter, The Raw I/O currently just shows some of the input and correct output. Do you want it to show your actual raw output?

  • After each "selection = getInput()" i inserted "System.out.print(selection)" to see the value of selection and it's different from the input in the results. For the other input i was able to

    cont...
  • i ad my code link, so you will have the right solution...

    my code

  • my code
    hey. im need help.. im didnt understand

  • Look at the general syntax of the switch statement. Here's one with only one case, which will print "word" when num is 1:

    switch (num) {
       case 1:
    
    cont...
  • Here is my code:

  • The example doesn't work. Input 2 gives a sum of 22, so shouldn't go back to 0, input 4 sums to 4 and again shouldn't be zero'd.

  • @Shane, those hands contain odd multiples of 3, which cause the score to be 0. I added some explanation above.

  • How do I resolve this?

    for (int i=1; i<cards.length; i++) {
    if (i%2!==0 && i%3!==0) {
    System.out.println(sum +=i);
    }
    }
    }

  • is there any hint? I'm stuck :(

  • static int doStuff(int[] cards){
    for (int i=1; i<cards.length; i++) {
    if (i%3==0) {
    break;}
    if (i%2!==0 && i%3!==0) {
    System.out.println(sum +=i);
    }
    System.out.println("0")

  • When you get a multiple of 3 remember that the whole hand gets to 0 no matter the cards before or after. Use break in that case.

  • Why are there no awnsers anywere?

  • Here is the awnser i forgot sum=0; before the break. devil in the details i guess.
    my code

  • OK I'm lost here...

    I think, according to the instructions my code is right. See the expected output. I think theres a mistake!
    Input Correct Output Your Output
    1 2 6 7 8 0
    1 2 4 5 7 9 0 0
    2 4 8 11 13 24 24
    1 2 3 4 0 0

    cont...
  • OK never mind LOOOOLL

  • I ended up resolving the problem using a type cast, as otherwise I received errors when adding to the char.

  • @no_name, that's one way though you don't need a cast. The following code works, and c can be incremented too. System.out.print(c+" ");

  • why is this incorrect?

    class Main{
    static void doStuff(char c){
    for (char c=a; c<=21; c=a+1) {
    System.out.println(c+"");
    }
    }

  • They should of have explained the difference between i=i+1 and i++, cause in this case this is not the same!

  • for(char i=c; i<=c+5; i++){
    System.out.print(i+" ");

  • @thales, they're basically always the same, but make sure you don't put i=i++ when you mean i=i+1.

  • I dont understand why it is giving me a compilation error:
    here is my code:https://www.learneroo.com/user_answers/2687389458

  • I think you meant to use int i instead of char i.

  • changing it to int i gave me the following output :
    97 98 99 100 101 102
    81 82 83 84 85 86
    100 101 102 103 104 105
    66 67 68 69 70 71

  • I just found out you have to use print instead of println... :(
    Why?

  • OK here's a better question:

    Why does inputting Q to this give 'b'. It should output Q!

    for(char i=c;i<c+5;i++){
    System.out.println(i+ " ");
    }

  • You're supposed to print each group of characters on its own line. If you print each individual character on its own line, the solution for the first challenge will end up being printed out for the second challenge.

    (You can always click on the Raw I/O button to see the full input and output)

  • easy :) System.out.print((long)a*(long)b*(long)365*(long)24);

  • last long(s) no nescesarry.
    long afstand= (long)a *(long)b*8760;
    System.out.println(afstand);

Contact Us
Sign in or email us at [email protected]