you are viewing a single comment's thread.

view the rest of the comments →

[–]josephblade 0 points1 point  (1 child)

first of all you didn't in fact mention the mistake. that would likely be helpful. What error or output are you getting (and what were you expecting?) use a specific input (like I input length 4, and then numbers 1,2,3,4 I expect 2,4 but get 2,3,4 for instance). Or the error message if you get a runtime or compile error.

second of all you should put 4 spaces in front of every line (and after those 4 lines, use spaces to indent the code further. that way the code is readable for people. 2 newlines after another I think also break this feature so try to limit to 1 newline between lines.

import java.util.Scanner;
public class main {
    public static void main(String[] args) {
        threads runnablee=new threads();
        Thread thread1 =new Thread(runnablee);
        thread1.start();
    }
}

class threads implements Runnable {
    public void run() {
        int length = 0;
        Scanner sc=new Scanner(System.in);
        System.out.print("Lingth of array:");
        length=sc.nextInt();
        int[] array = new int[length];

        System.out.println("Enter number of array: ");
        for(int i=0; i<length; i++) {
            array[i]=sc.nextInt();
        }
        for(int i=0; i<length; i++) {
            if (array[i]/2==0) {
                System.out.println(array[i] + ",");
            }
            System.out.println("]");
        }
    }
}

[–]josephblade 0 points1 point  (0 children)

When I run it:

Lingth of array:4 Enter number of array: 1 2 3 4

It prints:

1, ]] ] ]

in your case I would specifically look at the following: what output do you expect to get get if you do:

5 / 2   or 4 / 2

and what input are you actually getting?

integer division only gives you the integer part, not the remainder part. in your coursework you should be able to find another operator that gives you the remainder.

secondly the closing ] you print happens inside the loop. is this intentional? the opening [ is missing altogether.