I am not getting errors at all in my code but it is NOT doing what I want it to - at all. I understand that there is another question related to divisibility to 3 or 5 but I do not think the question relates, as our coding is built completely different. I also find that this answer, this other answer, or even this answer are not helping me, either.
Anyway, I am trying to use a simple boolean expression to determine if an expression is true or not, then if it is true or not printing different lines. The intended look I would get is something like:
3 is divisible by 3
3 is not divisible by 5
4 is not divisible by 3
4 is not divisible by 5
5 is not divisible by 3
5 is divisible by 5
and so on...
However, I'm getting this:
3 is divisible by 3
3 is not divisible by 3
3 is divisible by 5
3 is not divisible by 5
and so on...
Initial problem can be found here. Right now I am just experimenting with the code, trying to get myself to a better understanding of Java. I wanted to start by knowing how to separate integers that are divisible by the numbers from integers that are not divisible by the numbers and I figured the best way to test this was to print the lines out. I do not know if I am going in the right direction at ALL here. Can anyone either give me pointers on the current code I have, or some hints, such as links to the corresponding Java commands that I will have to use for this program to work. If you post code that works, so I can see what I should be doing, that is fine too but please explain it to me, then. I don't want to just know what to type, I am trying to develop a solid foundation of programming problem-solving.
Sorry if this is a terrible question, I am EXTREMELY new to programming in general and am completely self-teaching. Give me some pointers, and I can most definitely change the question!
package multiplesof3and5;
public class InitialProgram {
public static void main(String[] args) {
// TODO Auto-generated method stub
int integer1;
integer1 = 0;
boolean divisibleby3 = (integer1 % 3) == 0;
boolean divisibleby5 = (integer1 % 5) == 0;
for( integer1=0; integer1<1000; integer1++){
if(divisibleby3 = true);{
System.out.println(integer1 + " can be divided by 3");}
if(divisibleby3 = false);{
System.out.println(integer1 + " cannot be divided by 3");}
if(divisibleby5 = true);{
System.out.println(integer1 + " can be divided by 5");}
if(divisibleby5 = false);{
System.out.println(integer1 + " cannot be divided by 5");
}
}
}
}