Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

in comp sci 1 need help on understanding why i'm getting 42 errors :)

0 votes
asked Jan 6 by 3 molina william (170 points)
import java.util.Scanner;

import java.util.Arrays;

public class Main

{

private int[] list = new int[100];

private int count = 0;

public static void main(String[ ] args) {

Main lab = new Main( );

lab.input(); // Read from datafile

lab.process(); // Sort the array

lab.output( ); // Display output

}

public void input() {

Scanner reader = new scanner(numberString);

reader.useDelimiter("/");

while(reader.hasNextInt())

{

    list[count++] = reader.nextInt();

}

}

public void process() {

Arrays.sort(list, 0, count);

}

public void output()

       System.out.println("all the numbers in order:")

       for (int i = 0; i < count; i++)

            System.out.println(list[i] + " ");

            System.out.println();

            System.out.println("printing all the negative numbers:");

            int negative = 0

            for(int i = 0; i < count; i++)

            {

                negative++;

                System.out.println(list[i] + " ")

}

int pos = 0;

System.out.println("\nprinting all the postive numbers:");

for (int i = 0; i < count; i++)

{

    if (list{i] > 0)

    {

        pos++;

        System.out.println(list{i] + " ");

    }

}

System.out.println("\nthere were" + negative + "negative numbers and " + pos + " postive numbers ");

private static String numberString = "-68/-66/78/77/-64/-63/-62/-61/-60/-22/39/-20/38/43/42/-26/41/-69/-55/-54/69/68/-50/-12/-13/25/28/3/2/1/7/-14/6/32/-17/4/70/9/71/8/-59/59/56/55/-41/17/18/15/-45/12/-48/65/60/-72/48/-74/-76/44/47/-78/46/-30/-31/-32/-35/-37/-36/-39/10/-38/-2/-4/-6/51/53/-8/-9/50/92";

}

public void output2() {

    int n =65;

    System.out.println("searching the list for " + n);

    int index = arrays.binarysearch(list, 0, n);

    if (index < 0)

         System.out.println(n + " was not in list");

         else

         System.out.println();

}

1 Answer

+3 votes
answered Jan 7 by Peter Minarik (22,520 points)

When you compile your code the compiler tells you all the compilation errors. You just have to go one by one and fix them up.

I did it quickly for you and the "fixed" code is below. I say it's "fixed" because I only tested if the code runs and did not have time to validate if it's doing the right thing.

Your code had many syntax errors, missing braces, redeclared variables, variables declared in the wrong scope, typos and many other problems.

Please, see the "fixed" code here:

import java.util.Arrays;
import java.util.Scanner;

public class Main
{
    private int[] list = new int[100];
    private int count = 0;
    
    public static void main(String[ ] args)
    {
        Main lab = new Main();
        lab.input(); // Read from datafile
        lab.process(); // Sort the array
        lab.output( ); // Display output
    }

    public void input()
    {
        Scanner reader = new Scanner(numberString);
        reader.useDelimiter("/");
        while (reader.hasNextInt())
        {
            list[count++] = reader.nextInt();
        }
    }

    public void process()
    {
        Arrays.sort(list, 0, count);
    }

    public void output()
    {
        System.out.println("all the numbers in order:");
        int negative = 0;
        for (int i = 0; i < count; i++)
        {
            System.out.println(list[i] + " ");
            System.out.println();
            System.out.println("printing all the negative numbers:");
            for(int j = 0; j < count; j++)
            {
                negative++;
                System.out.println(list[j] + " ");
            }
        }
        
        int pos = 0;
        System.out.println("\nprinting all the postive numbers:");
        for (int i = 0; i < count; i++)
        {
            if (list[i] > 0)
            {
                pos++;
                System.out.println(list[i] + " ");
            }
        }

        System.out.println("\nthere were " + negative + " negative numbers and " + pos + " postive numbers ");
    }

    private static String numberString = "-68/-66/78/77/-64/-63/-62/-61/-60/-22/39/-20/38/43/42/-26/41/-69/-55/-54/69/68/-50/-12/-13/25/28/3/2/1/7/-14/6/32/-17/4/70/9/71/8/-59/59/56/55/-41/17/18/15/-45/12/-48/65/60/-72/48/-74/-76/44/47/-78/46/-30/-31/-32/-35/-37/-36/-39/10/-38/-2/-4/-6/51/53/-8/-9/50/92";

    public void output2()
    {
        int n = 65;
        System.out.println("searching the list for " + n);
        int index = Arrays.binarySearch(list, n);
        if (index < 0)
            System.out.println(n + " was not in list");
        else
            System.out.println();
    }
}
commented Jan 7 by 3 molina william (170 points)
thank you for the help really appreciate it :)
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...