import java.io.*;
public class AdamHmwk4 {
public static void main(String [] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int counter1;
int counter2;
int counter3;
String answer = "";
System.out.println("Welcome to Adam's skip-counting program!");
System.out.println("Please input the number you would like to skip count by.");
counter1 = Integer.parseInt(br.readLine());
System.out.println("Please input the number you would like to start at.");
counter2 = Integer.parseInt(br.readLine());
System.out.println("Please input the number you would like to stop at.");
counter3 = Integer.parseInt(br.readLine());
System.out.println("This is skip counting by" + counter1 + ", starting at" + counter2 + "and ending at" + counter3 +":");
while (counter2 = counter3) {
counter2 = counter2 + counter1;
counter3 = counter2 + counter1;
}
}
}
I am trying to make skip-counting program. When I compile this code, the line while(counter2 = counter3){
shows up as a Incompatible Types error. The compiler says it found an "int" but it requires a "boolean". Please keep in mind that I am a newbie, so I have not learned booleans in my Java class yet.
You can't compare values with =
, which is the assignment operator. Use ==
to compare your values. Change
while(counter2 = counter3){
to
while(counter2 == counter3){
Here's an introductory page for Java operators.