public static void main(String[] args) { // int[] list = new int[10]; int i; System.out.println("Enter numbers :"); Scanner input = new Scanner(System.in); for (i = 1; i < 100; i++) { while (input != 0){ // problem here , incompatible Scanner and int i = input.nextInt(); } } }
Ok. so i get what you said and ty for your help,but its not working with 0.only numbers more then 0.If i neter 0 i get Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed character class near index 525 (([-+]?(((((?i)[]|\p{javaDigit})++)|([\p{javaDigit}&&[^0]]((?i)[]|\p{javaDigit})?((?i)[]|\p{javaDigit})?(\,((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit}))+)))))|(((((?i)[]|\p{javaDigit})++)|([\p{javaDigit}&&[^0]]((?i)[]|\p{javaDigit})?((?i)[]|\p{javaDigit})?(\,((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit}))+)))|(\Q-\E((((?i)[]|\p{javaDigit})++)|([\p{javaDigit}&&[^0]]((?i)[]|\p{javaDigit})?((?i)[]|\p{javaDigit})?(\,((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit})((?i)[]|\p{javaDigit}))+))) like this: <pre lang="cs">public static void main(String[] args) { int i; System.out.println(&quot;Enter numbers :&quot;); Scanner input = new Scanner(System.in); for (i = 1; i &lt; 100; i++) { while (input.hasNextInt(8)){ //need 0 here i = input.nextInt(); //if(input.hasNextInt()){ } } } }</pre></pre>
while (input.hasNextInt()) { // ... }
input.hasNextInt(8)
hasNextInt(int radix)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)