# Thread: Evens odds & likes 7

1. Member
Join Date
Nov 2011
Location
Belfast
Posts
37
Rep Power
0

## Evens odds & likes 7

Hello I am fairly new to Java and I have been given a task by my tutor at uni,

From what I can see I have everything in the corect positions and the even print at the even numbers where they are supposed to and the odd prints at the odd numbers where they are supposed to.

But for the odd text (i+ " odd and Likes 7" ) i.e. divides by 7 I cant get it to print at the correct odd numbers, it prints directly after the
(i+ " even and Likes 7" )

I have pasted my code below this picture

/**

public static void main(String[] args) {

//Decalre loop limits
for( int i =1; i<31; i++){

//Code for odd numbers
if ((i%2 == 0) && (i%7 != 0)){
System.out.println(i+ " even");

// Code for even numbers
}else if ((i%2 == 1) && (i%7 != 1)) {
System.out.println(i+ " odd");

// Code for likes 7
}else if ((i%2==0) && (i%7==0)){
System.out.print(i+" even and likes 7");
System.out.println();

}else if ((i%2==1) && (i%7==1)){
System.out.print(i+" odd and likes 7 ");
System.out.println();

}
}
}//Main
}//Public Class

*/

Any help would be greatly appreciated .

Thanks Martyn

2. ## Re: Evens odds & likes 7

You need to recheck your conditions for mod 7.

3. ## Re: Evens odds & likes 7

simple error :D I'm a new programmer too somewhat. Your last else if line that states if it is odd and likes 7 is wrong. change the (i%7==1) to (i%7==0). simply just change the 1 to a 0 and it should work. Let me know if this helped :D

4. ## Re: Evens odds & likes 7

Was it really necessary to spoonfeed the answer? I could have done that. The point of my post was for the OP to think about the problem and think about a solution themselves.

5. ## Re: Evens odds & likes 7

sorry i'm new to the forum and kinda excited to find a bunch of people that have common hobbies as myself. just wanted to help.

6. Member
Join Date
Nov 2011
Location
Belfast
Posts
37
Rep Power
0

## Re: Evens odds & likes 7

Hello everyone and thanks for the help Ihave managed to figure out the problem and thank you Juncky for not spoon feeding me the answer I dont believe you learn this way. It turns out it was my modulas values however it was the values on the top lines of code as opposed to the bottom lines like I thought.

Heres a picture

Heres my new code

public static void main(String[] args) {

//Decalre loop limits
for( int i =1; i<31; i++){

//Code for odd numbers
if ((i%2 == 0) && (i%7 != 0)){
System.out.println(i+" even");

// Code for even numbers
}else if ((i%2 == 1) && (i%7 != 0)) {
System.out.println(i+ " odd");

// Code for likes 7
}else if ((i%2==0) && (i%7==0)){
System.out.print(i+" even and likes 7 \n");

}else if ((i%2==1) && (i%7==0)){
System.out.print(i+" odd and likes 7 \n ");

}
}
}//Main
}//Public Class

Thanks again everyone

7. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
15

## Re: Evens odds & likes 7

@KimChi93: welcome to you, and your enthusiasm! The tradition, or ethos, here is to help a poster to learn or understand, but not to spoon feed code: something which effectively *stops* them develop understanding. Someone is sure to draw attnetion to it if you do that - but I hope that doesn't stop you doing what you can, and posting your own thoughts whereever you feel they might be useful.

(Sometimes where I can see exactly what the problem is, but a hint or nudge has been given to the original poster, I find myself thinking *about* the problem. In this case, would allowing the trial numbers to be integers rather than whole numbers make a difference to how the code would be written?)