Note that there are some explanatory texts on larger screens.

plurals
  1. POdetect Consecutive number using boolean
    text
    copied!<pre><code>public class ConsecutiveChecker { public static void main( String[] args ) { java.util.Scanner keyboardReader = new java.util.Scanner(System.in); int number = keyboardReader.nextInt(); int w; int x; int y; int z; // w= fourth digit, x= third digit, y= second digit, z= first digit w = (number - (number % 1000)) / 1000; x = ((number - (number % 100)) % 1000) / 10; y = ((number - (number % 10)) % 100) * 10; z = (1000)*(number % 10); boolean isOneDigitConsecutive; isOneDigitConsecutive = (number &lt;= 9); boolean isTwoDigitConsecutive; isTwoDigitConsecutive = (w = 0) &amp;&amp; (x = 0) &amp;&amp; (y &lt;= 9) &amp;&amp; (y - z ==1); boolean isConsecutive = (isOneDigitConsecutive || isTwoDigitConsecutive || isThreeDigitConsecutive || isFourDigitConsecutive) System.out.println(); } </code></pre> <p>}</p> <p>Hi, I'm new to Java and I have to write a code that detects whether a 4 digit number(user entered) is consecutive or not using boolean variable. Consecutive as in 0543, 1234, 0009, 0034(a single digit counts as consecutive). I've written this part of code until now, the problem is I don't understand why is my line<br> boolean isTwoDigitConsecutive; isTwoDigitConsecutive = (w = 0) &amp;&amp; (x = 0) &amp;&amp; (y &lt;= 9) &amp;&amp; (y - z ==1); wrong. it says that i can't use &amp;&amp; with Int.</p> <p>I would like to have some clarifications on how to use boolean variable.</p> <p>Thank you in advance.</p> <p>*edit: Thank you for your help, I listened to your advice and changed my code accordingly. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload