Java Language Details Comments
Comments
-
@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
check this by checking the previous submissions page. Here all results are listed. I could be mistaking but i think second input is a 2 instead of a 0.
It would help if Raw I/O would show all the input and output. If the first values are correct and only other input is incorrect it's difficult to find the problem with the 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" whennum
is 1:switch (num) { case 1:
System.out.println("word"); break; }
You need to use the switch statement to print a day of the week for each number from 1 to 7, and
default
to "Not a day" for other numbers. -
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 01 2 6 7 should return 0 because 6%3==0!! Why are you saying it should equal 8???
My code:
int score=0;for(int i=0; i< cards.length; i++){ if(cards[i]%3==0){ return 0; } else if(cards[i]%2 != 0) { score+=cards[i]; } } return score;
-
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 meani=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 ofchar 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);
Lukas Dancak
Mar 20, 4:37 PMWhy is (1) incorrect? Can not I write :
for(int num : array1){
if(num%2!=0 && num<200){
System.out.println(num);
}
}