Jump to content

Java Arrays help!

JoshuaTjandra

Not many people are good at Code here on these forums. If you have questions about code, try and find a code forum :D (Or reddit :P)

I'm the Forum Owl


*Who*


 

Link to comment
Share on other sites

Link to post
Share on other sites

I don't know much about Java, but PLEASE:

Next time you post source code, put it in the code-Brackets (<>). This will make life easier for you and for the people who wnat to help you :)

public class Utility{    public static void main (String[] args)    {        double[] array1 = {1,22,333,4444,55555};                for( double value : array1 )            System.out.printf("     %f", value);                if (ascendingOrder(array1))        System.out.println("\nTrue");        else            System.out.println("\nFalse");                int [] array3 = {0,1,3,2,3,0,3,1};        int x = 3;                removeTwo(x,array3);        for (int value : array3)            System.out.printf("%d",value);    }            public static boolean ascendingOrder(double[]array2){   for(int i=0; i<array2.length-1;i++)    {        if(array2[i]>array2[i+1])            return false;    }    return true; }        public static int[] removeTwo (int x, int[] array3)    {        int counter = 0;        boolean[] barray = new boolean [array3.length];        for (int k=0; k<array3.length; k++)        {            barray[k] = (x == array3[k]);            counter++;        }             int[] array4 = new int [array3.length - counter];         int num = 0;         for (int j=0; j<array3.length; j++)    {         if(barray[j] == false)        {            array4[num] = array3[j];            num++;        }             }         return array4;    }     }

MB: MSI Z77A-GD55 | CPU: Intel i5-2500k @ 4.5 GHz | RAM: 8GB Kingston DDR3 @1333MHz | GPU: Asus GTX 770 DirectCU II 

Monitor: 22" Samsung SyncMaster B2230H @60Hz | Audio: Creative Aurvana Live! | PSU: SuperFlower 80+ Gold 550 Watt 

OS: ArchLinux + KDE / Windows 8 Pro 64bit | Smartphone: Nexus 4 16GB - CM11

 

Link to comment
Share on other sites

Link to post
Share on other sites

Not many people are good at Code here on these forums. If you have questions about code, try and find a code forum :D (Or reddit :P)

pfff ....

 

public class Utility{    public static void main (String[] args)    {        int [] array3 = {0,1,3,2,3,0,3,1};        int x = 3;          removeTwo(x,array3);        public static int[] removeTwo (int x, int[] array3)    {        int counter = 0;        boolean[] barray = new boolean [array3.length];        for (int k=0; k<array3.length; k++)        {            barray[k] = (x == array3[k]);            counter++;        }                // HERE!!!        // array3.lenght == 8        // counter == 8         int[] array4 = new int [array3.length - counter];        // THE LENGTH OF THE ARRAY 4 IS ZERO !!!!         int num = 0;         for (int j=0; j<array3.length; j++)    {         if(barray[j] == false)        {            array4[num] = array3[j];            num++;        }             }         return array4;    }     }

Mini-Desktop: NCASE M1 Build Log
Mini-Server: M350 Build Log

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×