# Egzon Krasniqi

Greenhorn
since Feb 10, 2019
Cows and Likes
Cows
1
In last 30 days
1
Total given
0
Likes
0
0
Total given
0
Given in last 30 days
0
Scavenger Hunt
Ranch Hand Scavenger Hunt
Greenhorn Scavenger Hunt

## Recent posts by Egzon Krasniqi

salvin francis wrote:Yes, I think 10 would be correct. Can you share your code where you arrived at those values ?

3 days ago

salvin francis wrote:

This means that the lamp 100 would be on

Total 10 ? Correct ?
3 days ago

Campbell Ritchie wrote:If you are getting nine lamps alight please tell us their numbers.

Thank you and sorry for taking your time i dont know what to do anymore

Lamps ON : 1,4,9,16,25,36,49,64,81
3 days ago

Campbell Ritchie wrote:Just this time, since you are new, I have added code tags to your post, and doesn't it look better. Please confirm whether this is the real code you are using, because the spelling error in setIsOFF() will cause you serious problems. It would be much simpler if you called the boolean “on”, and started the name of the method with a boolean return type is.

Thank you i dont see the comments i dont know why i will look at it again.
3 days ago

Campbell Ritchie wrote:Please post what you have, even if it isn't complete.

Is it right ?
3 days ago

Liutauras Vilda wrote:

Egzon Krasniqi wrote: i will try it in my own way i just need the answer "how much lamps are ON at the end" to test my code if its right ?

Please write the code and post it here, so somebody could run it and verify its correctness (or not).

But in general I think, that if you'd understand the problem, you wouldn't question your algorithm whether it is correct or not. To me seems that you didn't spend enough time trying to understand the problem. And that is really the crucial part in any problem.

Campbell Ritchie wrote:Please post what you have, even if it isn't complete.

Here i have the code i write it in 2 classes I dont know exactly if its right or not at the end are total 9 lamps ON :\ I practice this work on my notebook and it should be 40 lamps ON !

---------------------------------------------------------------

----------------------------------------------------------------------

5 days ago
Thanks to everyone for such a good advices i will post my code as soon as i think it is ok
6 days ago

Campbell Ritchie wrote:

Egzon Krasniqi wrote:. . . Person number 3 enter the ROOM and switch OFF lamps 3 , 5 , 7... . . .

Surely that is 3, 6, 9....

. . . can someone tell me is this right ? . . .

I can tell you. It isn't correct. Not even if it gives the same result as I found this morning is it correct.
The error is in the line with % in. After that line, any correct results are there by luck, not good programming.
There are also design and style problems.
• 1: Everything is crammed into the main() method, which is far too long.
• 2: Never use == true and == false; they are poor style and very error‑prone.
• 3: Don't switch booleans with an if‑else. Use lamps[j] = !lamps[j];
• 4: There is no need to copy numbers into a second array; you can traverse the first array and print the results from that.

• Thanks for advices man i will try it in my own way i just need the answer "how much lamps are ON at the end" to test my code if its right ?
6 days ago

Daniel Demesmaecker wrote:

if((j+1) % (i+1) == 0){

that can never be true...
And that's only one of the many issues.
you need a nested for loop to itterate the lamp and the persons, 1 int for the interval and a final foreach to print the state of the lamps at the end, that's it...

Okay i will try it
6 days ago

Daniel Demesmaecker wrote:I haven't even read the could, but I already can tell you this, if you would turn in this code at my professir, he would flunk you for sure. Just alone by the way it's formatted, and on first look, it seems way to mutch ocde for what you were trying to do

Is this forum to help or what ? i am beginner at java i just tried to do ?
6 days ago

Carey Brown wrote:

Egzon Krasniqi wrote:Lamps in the ROOM are OFF at the beginning.

If you make an boolean array at the start all are FALSE (off);

Do you have the code to do this much?

This is the code that a friend send me can someone tell me is this right ? at the end are 10 lamps on ?

public class ROOM{
public static void main(String [] args){
boolean [] lamp = new boolean [100];
int countTrue = 0;
int index = 0;

for(int i = 0; i < lamp.length; i++){
for(int j = 0; j < lamp.length;j++){
if((j+1) % (i+1) == 0){
if(lamp[j] == false){
lamp[j] = true;
}
else{
lamp[j] = false;
}
}
}
}

for(int i = 0; i < lamp.length; i++){
if(lamp[i] == true){
countTrue++;
}
}

int [] lista = new int [countTrue];

for(int i = 0; i < lamp.length;i++){
if(lamp[i] == true){
lista[index++] = i+1;
}
}
System.out.println();
System.out.println();

System.out.print("at the end on are :" + countTrue + " lamps.And the lamps that are on: ");
for(int i = 0; i < lista.length;i++){
System.out.print(lista[i] + ", " );
}
}
}
6 days ago
I dont have any idea how to write the code, i will try it but can you tell me at the end how much lamps are ON ?
6 days ago
I dont understand..

Lamps in the ROOM are OFF at the beginning.
Outside are 100 persons.
Person number 1 enter the ROOM and switch all lamps ON because all are (off);
Person number 2 enter the ROOM and switch OFF lamps 2 , 4 , 6.. because all are ON..
Person number 3 enter the ROOM and switch OFF lamps 3 , 5 , 7...

If you make an boolean array at the start all are FALSE (off);
6 days ago