My stupid FOR loop doesnt work to create a new array, help!

Hello, I need help creating a new integer array that contains exactly one of each element a different array.
My original array is called co[]
lets say it has the values: 1213445232
I want my new array called classArr[]
for example, it would end up being: 12345
my integer array is called classArr[]. and i want it to store exactly one of each element from the co[] array. Here is my code. It compiles without errors, but I get out of bounds exception when i run it.
classArr[0] = co[0];
int temp = 1;
for (int k = 0; k < x; k++) { //x is the number or elements in co[]
     for (int j = 0; j < temp; j++) {
          if (classArr[j] != co[k]){
                classArr[temp] = co[k];
                temp++;
System.out.println("Values in new array");
for (int c = 0; c < temp; c++){
     System.out.println(classArr[c] + " ");
} Thanks for your help!!!!

im pretty sure the initialization of the variables are
set right.Well, without seeing the initialization I doubt I can help you. Try to figure out if it is classArr[temp] or co[k] that causes the exception. (Hint: put them on two different lines.)
x is the number of elments in the co[] arrayTry replacing it with co.length.
classArr[] is a dynamic array set to a number, lets
say it's abcWhat is a "dynamic array" in your terminology? And what is "abc"? Please provide at least the declarations of your arrays.

Similar Messages

  • Steadyshot stabilization for video doesnt work since Lollipop update. HELP!

    Where should I send information about SERIOUS issue of new Lollipop on XPERIA Z3? Since last update from Kitkat the SteadyShot stabilization for video doesnt work (intelligent mode works standard). Previously great videos are now shaky and simply ugly. Please SONY make something with that on next update. Probably Ill have to sell my Z3 if there will be no patch. Im filmaker who needs good video quality in his smartphone.

    i tried both...still inteligent works as standar what means stabilization is very poor...here more info about that lollipop bug found on the net http://forum.xda-developers.com/z3-compact/help/steadyshot-intelligent-active-gone-t3106177

  • Swipe for Keyboard doesnt work. Dont spend the 1.99!

    Swipe for Keyboard doesnt work. Dont spend the 1.99!

    See:
    iOS: Troubleshooting applications purchased from the App Store
    Contact the developer/go to their support site if only one app.
    Restore from backup. See:
    iOS: How to back up              
    Restore to factory settings/new iPod

  • My dad and I have shared an iTunes account for years and I just created a new apple id but I have no Idea how to get all those purchases to this new account. Help please?

    My dad and I have shared an iTunes account for years and I just created a new apple id but I have no Idea how to get all those purchases to this new account. Help please?

    The old Apple ID (presumably your dads) owns those songs and your new Apple ID does not.  However, your dad can authorize your iD to use the songs by going to Store > Authorize This Computer from your iTunes menu and entering his Apple ID and password.

  • How to create an new array from dynamically discovered type

        public static Object toAdjustedArray(Object source, Object addition,
                                             int colindex, int adjust) {
            int newsize = 0;
            Class componentType = null;
            if (source.getClass().isArray()) {
                Object[] arrayIn= (Object[])source;
                componentType = arrayIn[0].getClass();
                newsize = arrayIn.length + adjust;
            else {
                System.out.println("error in ArrayUtil");
            Object[] newarray = new Object[newsize];
            copyAdjustArray(source, newarray, addition, colindex, adjust);
            return newarray;
        }This methods take an array as an input an append new value(s) to it.
    I can get the component type of the array (i.e. the class of the array's member). But how can I create a new array of this component type (i.e doing something like componentType[] newarray = new componentType[newsize])?
    CU Jerome

    I fanally found a walkaround trick for my problem.
    Their is no way to create an array of a certain type (dynamically dsicovered) in CLDC. But what you can do is to use the instanceof method to determine the type of your array and in a big if statement create the right array.
    Here is the final code:
        public static Object toAdjustedArray(Object source, Object addition,
                                             int colindex, int adjust) {
            int newsize = 0;
            if (source.getClass().isArray()){
                Object[] arrayIn= (Object[])source;
                newsize = arrayIn.length + adjust;
            Object arrayElement = null;
            if (addition.getClass().isArray()){
                Object[] temp = (Object[])addition;
                arrayElement = temp[0];
            else{
                arrayElement = addition;
            Object newarray = null;
            if (arrayElement == null){
                newarray = new Object[newsize];
            if (arrayElement instanceof org.hsqldb.Index){
                newarray = new org.hsqldb.Index[newsize];
            else {
                newarray = new Object[newsize];
            copyAdjustArray(source, newarray, addition, colindex, adjust);
            return newarray;
        }

  • I had to restart my mac and couldn't remember my password and had to create a new keychain, help?? i just want to stop all these pop up screens coming up now, how do i retrieve my original password?

    i had to restart my mac and couldn't remember my password and had to create a new keychain, help?? i just want to stop all these pop up screens coming up now, how do i retrieve my original password?

    I'm not quite sure I understand what you're saying? Have you gained access to your mac, but getting pop-ups about your old password? If you have access, you could always copy important files and reinstall OS X from scratch. Also you could use the Mac as an external hard drive if you have another Mac doing the same. Those are probably the easiests ways. If it was easy to just go ahead and change passwords as so, security would be an issue. How is your computer locked? Is it a filevault password, or how much do you have access?

  • For loop not working & way to include an external file

    Hi everyone, i am new to java and am having some problems with my program.
    I have a for loop but it doesnt work it completely gets ignored and i have
    no idea why it does that.
    IS there a way that i add another option in the menu to open an external file
    which would be similar to this but it would be for cabinBooking. If so how do
    i do that. if opening an external file is impossible then could you please show me an example of how to extend the booking class.
    Any help would be appreciated.
    Thank you very much
    import java.util.Scanner;
    import java.io.*;
    public class Booking{
    Booking(String bId,     String bName,int bNum){
    bookId = bId;
    bookName = bName;
    bookNum     = bNum;
    String bookId;
    String bookName;
    int     bookNum;
    public double calculateBookingPrice(){
    double cost     = bookNum *     genBookingcost;
    return cost;
    double genBookingcost =     80;
    public void     summary(){
         System.out.println();
    System.out.println("Booking Number is: " + bookId + ", ");
    System.out.println("Booking Made for : " + bookName);
    System.out.println("Cost of booking = $" + calculateBookingPrice());
    System.out.println();
    public static void main(String[] args) throws IOException{
    Scanner     keyboard = new Scanner(System.in);
    BufferedReader charInput = new BufferedReader
    (new InputStreamReader (System.in));
    int bookCount = 0;
    char answer;
    Booking[] bookings = new Booking[6];
    do {
         menu();
         System.out.println("book Count = " + bookCount);
         answer = charInput.readLine().charAt(0);
                   if (answer == 'a' || answer == 'A'){
                        System.out.println("Booking     ID : ");
              String idstring     = keyboard.nextLine();
              System.out.println("Booking     Name : ");
              String namestring =     keyboard.nextLine();
              System.out.println("number of people : ");
              int     ppl     = keyboard.nextInt();
              bookings[bookCount] = new Booking(idstring,namestring,ppl);
              bookings[bookCount].summary();
                        bookCount++;
                   }else if (answer == 'b' || answer == 'B'){
                        System.out.println("Enter printing");
                        bookings[0].summary();
                        bookings[1].summary();
                        // this is the loop that it is ignoring GGRRRR!!!
                   for(int i = 0; i >= bookCount; i++){
                        System.out.println("Counter: " + i);
                        bookings.summary();
                   }else if (answer == 'x' || answer == 'X'){
                        System.out.println("Exiting the programme...");
    System.out.println();
    System.exit(0);
    }while (answer != 'x' || answer != 'X');
    public static void menu(){
         System.out.println("********** Main Menu ***********");
              System.out.println(" A. Make General Booking");
              System.out.println(" B. Print Summary");
              System.out.println(" X. Exit program");
              System.out.println("*****************************");
              System.out.println("Select one of the options above");

    in order to extend the Booking class, you can create anew class like this..
    public class CabinBooking extends Booking
       public CabinBooking( /*String bId, String bName,int bNum .. more args or fewer, or none.. */)
        // add new methods or override ones from Booking
    }

  • Javascript For loop not working within a function

    Hi all,
    I'm a beginner to LiveCycle and I cant seem to get a loop working within a function.  The function is being called successfully because when I manually create the code it works but I am trying to clean things up.
    So here is my working example:
    function hideContent() {
            MainFlowedSub.LevelsSub.Table1.presence = "hidden";
            MainFlowedSub.LevelsSub.Table2.presence = "hidden";
           ... and so on....
             MainFlowedSub.LevelsSub.Table8.Row1.presence = "hidden";
            MainFlowedSub.LevelsSub.Table8.Row2.presence = "hidden";
           ... and so on....
    However when I try and creat a loop instead of listing every sing table/row nothing happens. this is important to my project as there will be alot of different rows depending on radio button selections earlier in the form.  Below is the current state of my code:
    function hideContent() {
        var i=0;
         for (i=1;i<=5;i++)
             MainFlowedSub.LevelsSub.Table[i].presence = "hidden";
        var j=0;
         for (j=1;j<=23;j++)
             MainFlowedSub.LevelsSub.Table8.Row[j].presence = "hidden";
        var k=0;
         for (k=24;k<=88;k++)
             MainFlowedSub.LevelsSub.Table8.Row[k].presence = "hidden";
    this will then continue as there will be hundreds of rows.
    Any help will be greatly appreciated and I am sure I am making a basic error  so thanks in advance.
    j

    thanks for your help paul.  Again, really appreciated as I know very little about all this.
    Unfortunately its still not working... One thing I am sure of is that I am doing something very basic wrong. So here is my code, I have applied your suggestion above which will cover all my data:
    To give an understanding, I have 5 tables of content, each has i amount of rows. and I am running this script to clear/remove all items being displayed.
    function hideContent() {
        for (var i=1;i<=5;i++)
            xfa.resolveNode("MainFlowedSub.LevelsSub.Table[" + i + "]").presence = "hidden";
        for (var i=1;i<=71;i++)
            xfa.resolveNode("MainFlowedSub.LevelsSub.Table8.Row[" + i + "]").presence = "hidden";
        for (var i=1;i<=93;i++)
            xfa.resolveNode("MainFlowedSub.LevelsSub.Table9.Row[" + i + "]").presence = "hidden";
        for (var i=1;i<=99;i++)
            xfa.resolveNode("MainFlowedSub.LevelsSub.Table10.Row[" + i + "]").presence = "hidden";
        for (var i=1;i<=101;i++)
            xfa.resolveNode("MainFlowedSub.LevelsSub.Table11.Row[" + i + "]").presence = "hidden";
        for (var i=1;i<=87;i++)
            xfa.resolveNode("MainFlowedSub.LevelsSub.Table12.Row[" + i + "]").presence = "hidden";
    It has to be something to do with my For loops because if I manually insert each line it works perfectly.
    Thanks again,
    johnny

  • OSB - Resume in Foreach Loop doesnt work

    Hi,
    I have used for each loop in osb proxy service message flow, and in the stage error handler i am using a resume action to resume the for loop in case of error for any loop.
    But then it actually doesnt work. In case of error it continues to next stage instead of resuming the for loop.
    Can any one suggest any solution for this? I searched for fourms and was not able to get the exact solution. Was wondering what the problem is. Any suggestions on this? Appreciate your help. Thanks
    Note: I cannot use split join as i have to do sequencial invocations and in case of error from any invocation i need to log it and continue the for loop, which as per my knowledge is not possible using split join. Let me know if i am wrong. Thanks
    Edited by: 791951 on Mar 10, 2011 9:02 AM

    Thanks for replying. Nope I cannot call that proxy again from the error handler.
    Below is the Message Flow
    Proxy Service gets the Status as Input Field
    Request Pipeline:
    Then in the request pipeline proxy takes the status as input and queries DB for the messages (MessageID/Message) with that particular status.
    Once it retrieves all the messages for each record of the queried record i use a for loop and post all the messages to an Advanced Queue.
    So if there is any message which actually fails then if i call the PS again it again resubmits the messages which actually passed, which is not my requriement.
    Please suggest why resume is not working. Appreciate your help. Thanks

  • Jsp variables to javascript array, for loop dont work.

    This works fine. con.getmake passes a different variable each time to the javascript array using a manual index.
    <script>
    make[0] = "<%= con.getmake() %>" ;
    document.write(make[0]);
    make[1] = "<%= con.getmake() %>" ;
    document.write(make[1]);
    make[2] = "<%= con.getmake() %>" ;
    document.write(make[2]);
    make[3] = "<%= con.getmake() %>" ;
    document.write(make[3]);
    </script>
    If I try and do the same with a for loop, It seems as though all the elements hold the same first variable retrieved from con.getmake, I am not getting the next variable from my java class.
    <script>
    for (var i= 0; i <= 2; i++)
    make[i] = "<%= con.getmake() %>" ;
    document.write(make);
    </script>

    Hi,
    Java is parsed once on the server which creates a HTML page, then it is passed to the client's browser where the javascript is executed. So con.getmake() is only executed once in java. You've got to execute your loop in java not javascript :
    <script>
    <%
    for (int i= 0; i <= 2; i++)
    %>
    document.write("<%= con.getmake() %>");
    <%
    %>
    </script>

  • Since I updated to firefox 5.0, the windows media player plug in for firefox doesnt work anymore :(

    Ok I recently upgraded to firefox 5.0, and then when I went to a website that uses windows media player to watch videos and news reports, it said I needed to download the windows media player plug in for firefox. And yet I had already done that in the past. So it directs me to the plug in for windows media player 11, I download and install and it doesnt work. Website repeats the same message, you need to download plug in. It was working fine with firefox 4.0! I use the OS Windows 7, 64bit. Any help please?

    Yes I did, at first it identified it as already there, so it gave the option of repairing it, etc, so I uninstalled the Windows Media Player, then Installed it again, and it still doesn't seem to work! I have the same problem with several other plug ins, in the add ons and plug in section of Mozilla tools, I see that say, "incompatible with firefox 5.0" but as days go by those add-ons, that are built by those other websites seem to be repairing it, but I wanted to know for something as important as windows media player plug in, am I the only one getting this problem? :/

  • How come script for cursor doesnt work in jsp pg?

    it works in an html pg but it doesnt work in a jsp page when i put in a javascript for an animated cursor btw the body tags:
    <script>blah</script>
    WHY? thanks

    WHY?Because it doesn't like you.
    View source on the generated JSP page.
    Compare it to the html page.
    Save the source as a static html file.
    Find what is causing the problem - maybe a javascript error on the page that prevents your code running?
    If you have IE, Tools:options: advanced tab, and uncheck "disable script debugging" so you can see the error messages - or get a browzer with a decent javascript debugger.
    Good luck,
    evnafets

  • Conditional Loop doesnt work correctly.

    Hi There,
    If you analyze my code, its all about parsing a dictionary.
    Im checking the dictionary for the "aardvark" word. It gives me
    false all the time. When "aardvark" is the first word in the array,
    i.e my_dictionary[0] is "aardvark". I wonder why the conditional
    loop isnt working fine. Im checking if the user string aardvark is
    == my_dictionary
    ; it should be giving me the true value.
    Is there any error in the code? Can anyone explain me where
    im going wrong?
    P.S -> The traces put everywhere gives me the right
    output. Except for the result of the if().
    Regards and thanks a lot in advance.
    Roshan Kolar

    Hi Raymond,
    Thanks for the reply. I got the problem, actually the
    conditional loop was perfect, the parsing was not. The reason
    being, some words in the dictionary had a Space/NewLine/Carriage
    Return at the last index after the word. It was all random, so some
    words were taken, but some were not like "vicious" == "vicious " -
    gave INVALID WORD.
    So I redesigned the parser, where I removed the unwanted last
    char - now the condition worked fine. Thank god I was working even
    after posting the query.
    Thanks a lot Raymond.
    Regards,
    Roshan

  • [Struts]File upload doesnt work with "Create" but works with "CreateInsert"

    Hello,
    thank you for reading this!
    Im facing serious issue with web application built with JSP, Struts & ADF BC in jdeveloper 10.1.3.1 and jdeveloper 10.1.3.2 (same code works perfectly in older jdev versions)
    File upload to DB only works if CreateInsert is selected in PageDefinition. (Have to change from default "Create" to "CreateInsert")
    If I set "Create" i get this problems:
    - if VO is empty the row cannot be created (no error is returned, i click ОК and row is not commited, its just discarded)
    - if VO is not empty instead to create new row current row is updated.
    This only happens with "multipart/form-data" forms. With plain form row is created without the problem.
    If I change to "CreateInsert" then I can add new rows with "multipart/form-data" but i would prefer "Create" because it avoid the blank row issue...
    Old 10.1.3 works with "Create" and "multipart/form-data".
    Im aware of this problem since the 10.1.3.1 release but I havent posted on the forum because I hoped Oracle is aware of this problem but since the problem remains I decided to react. I do not have the metalink account so only way to address the issue is in this forum.
    Please Help.
    Sanja

    I had some problem with 'Create' earlier with 10.1.2. Then I kept recreateing the pages and then it worked finally. How are you creating the page for 'create' event. Is it like, first displaying the rows from the table with create button, or are you right away creating the page from menu option.

  • My bluetooth for ipad doesnt work

    My bluetooth for my 1st gen ipad doesnt work it searches, takes a while to find anything and then it says it cant connect. Any reasons or solutions to my problem same thing goes on for my iphone 3g and iphone 4 but im more worried for the ipad since its what i use more. ps no warranty because i

    Are you trying to tether? because that is supported over wifi. you can use icloud to get some data to sync. bump can also transfer certain data like contacts or photos.

Maybe you are looking for

  • How can you find the Last Modified Date of a particular table

    Hi, I want to show to the LAST MODIFIED date of a particular table to the user before refreshing the table with new data. Experts please suggest me the way using JDBC-SQL connection.

  • Want boot up

    Can I get a boot disk that will boot windows vista without loosing what I have on my hard drive? L305-S5921.

  • Pass parameter to sql statement in query manager

    Hai to all,            I want to pass the percentage  as the parameter into the sql statemnet.i what to execute it in the query manager.           If i execute that statement then cann't found the tablename error is coming.          Other than the da

  • How to resolve the java.sql.SQLException: OALL8 is in an inconsistent state

    Hi All, I am getting the SQLException "java.sql.SQLException: OALL8 is in an inconsistent state." and in finally block while I am trying to execute another operation on the same database getting another exception "java.sql.SQLException: Io exception:

  • Authentication for user denied in realm weblogic

    Hi, I was testing distributing EJB's to different server with their client and kept hitting my head to the wall with the following problem almost the whole day: Stacktrace = javax.naming.AuthenticationException. Root exception is java.lang.SecurityEx