-3

im actually pretty new into java , my homework was to create a array . After a while of searching for a good video i found this .

--

If i compile this blue j shows me that "int 1=0;" is not a statement .

Can someone tell me where the mistake is ?

Thanks for helping


import java.util.*;

class binarysearch
{
     public static void main ()
     {


    Scanner sc= new Scanner (System.in);
    int num[]= new int [] {23,34,45,56,67,78,89,90,12};
    System.out.println("Enter the Number to search");
    int n=sc.nextInt();
    int u=num.length-1,mid=0;
    int 1=0;



    int c=0;


        while(1<=u)
        {    

        mid=(1+u)/2;
        if(n<num[mid])
             u=mid-1;
        if(n>num[mid])
             1=mid+1;
        if(n==num[mid])
        {
             c=1;
             break;

        }     


    }
    if(c==1)
    System.out.println("search successful"+"\n"+"this number " +n+ "position" +(mid+1));
    else
    System.out.println("Number not found");
  }
}
Ayush
  • 741
  • 9
  • 19
Y.KI
  • 1

1 Answers1

0

1 is an invalid variable name. With that declaration, you are basically telling Java to re-create math. Thus, int 1 = 0; is impossible to compile.

Consider restating the constructor:

int i = 0;
Cardinal System
  • 2,749
  • 3
  • 21
  • 42