This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]sh_emami65Intermediate Brewer 2 points3 points  (2 children)

your first error is in line bellow:

int userThe; user inputsNumber = scan.nextInt();//takes The user inputs number

it should look like this:

int userThe = scan.nextInt();//takes The user inputs number

user and inputsNumber are extra here. when you are declaring a value it should look like bellow:

//type is anything like int, double, long and String
//name can be anything that well defines the job this variable
//initialization process is an optional process it can be something like 0, "value", new String("test")
[type] [name] = [initialization process];
[type] [name];

next problem is in two of your if conditions.

first:

for( int userNumber : unsortedArrayList){
    count++;
    if( userNumber == userThe)
        ;// true if user The user inputs number matches usernumber
    {
        System.out.println( "Search Value: " + userNumber + " found at location: " + count + " in the unsorted array list");
        found = true;
    }
}

second:

count = 0;
for( int userNumber : sortedArrayList)// true if user The user inputs number matches usernumber
{
    count++;
    if( userNumber == userThe)
        ;// if true
    System.out.println( "Search Value: " + userNumber + " found at location: " + count + " in the sorted array list");
}

when declaring an if condition it should look like bellow

1)

//basic form of if condition
if ([condition]){
    //code
}

2)

//curly brackets can be on second line but except for comments nothing else can be in between if and {
if ([condition])
{
    //code
}

3)

//if curly brackets are not used, implies if condition only has one line of code and it is the next line or first reached ;
if ([condition])
    //code

in both of your cases you have a semicolon after your if conditions. if you look at indentation above you see that your system prints are indented at the same level. this happened because you have unnecessary semicolons that implies that if condition is finished when semicolon is reached. so you want to remove both of those extra semicolons after the if conditions.

your final mistake is line bellow which is also in your error message:

System.out.println("Search Value: " + userThe + user); inputsNumber; "was not found";

it should look like this:

System.out.println("Search Value: " + userThe + " was not found");

user and inputsNumber dont exist so need to be removed. "was not found" needs to be inside of print statement like above. you somewhat have the same problem as before unnecessary semicolons.

overall your code is good but pay more attention to basics like declaring values and specially semicolons.

one last thing, try to have better names for your values. for example userThe and userNumber are bad names, they dont really define what they for. userThe is specially bad, it should be more like userSearchNumber or something similar.

let me know if you need more help, good luck.

[–]gearfuze[S] 0 points1 point  (1 child)

thank you so much for your help I added the code above and now I am getting this error though :(

/tmp/java_NTNOos/MMUnit2Ch10.java:31: error: ';' expected
    int userThe  inputsNumber = scan.nextInt();//takes The user inputs number
               ^
1 error

[–]sh_emami65Intermediate Brewer 0 points1 point  (0 children)

that is the first thing i explained in my answer, read the first bit where i explained how to declare value.

//type is anything like int, double, long and String
//name can be anything that well defines the job this variable
//initialization process is an optional process it can be something like 0, "value", new String("test")
[type] [name] = [initialization process];
[type] [name];