Table initialization problem.

Hello

I am new to Java, so I ran into a little problem.
import java.util.Scanner;

class Inventory{
public static void main(String [] args){
Scanner scan = new Scanner(System.in);
System.out.println("How many items do you want to store?");
final int length = scan.nextInt();
String items[] = new String[length];
System.out.println("You can store "+items.length+" items:");

for(int i=0;i<items.length;i++){
items[i] = scan.nextLine();
}
System.out.println("\nYou have stored:");
           
for(String s:items){
System.out.println(s);
}

}
}
If basically as you can judge by the code, this little program is supposed to ask the user for input on the number of items it wants to store in the table. And then on the user input value, the size of the array will be defined so that it will ask you to store as many elements he needed.

The problem is, if I want to store 5 items for example, I type in 5 and I can store only 4 points. I thought that the paintings were supposed to start with an index of 0, so if I put 5 be stored 5 items (from 0 to 4), but instead it stores only 4... What could be the problem? First I thought it was the loop and published as "I < = items.length" but there was an OutOfBounds exception or something.

I would appreciate your help, I need a detailed explanation that I want to understand how things work once and for all.
Thank you

Published by: 884351 on Sep 9, 2011 13:38

Published by: 884351 on Sep 9, 2011 13:39

I'm sorry I'm new here and don't know the code tags. However, the problem is that if I enter 5 as the size of the array it stores only 4 elements of what I noticed, is if I use
scan.next()
Instead of
scan.nextLine()
for inputs of the element of analysis, it works fine. So would it be possible that after I have the size of the input array and press the
scan.nextLine
takes the value of the input and stores it in the index 0 points [0]?

Published by: 884351 on Sep 9, 2011 15:01

884351 wrote:
The problem is, if I want to store 5 items for example, I type in 5 and I can store only 4 points.

No it's only your support.

I thought that the paintings were supposed to start with an index of 0, so if I put 5 it must store 5 items (from 0 to 4),

Yes your quite right.

but instead, it stores only 4... What could be the problem? First I thought it was the loop and edited like

No problem in the loop, he works in the way you run it. I say give Sysout loop and check, why he doesn't want input first.

I will say that it is how you use the scanner.

takes the value of the input and stores it in the index 0 points [0]?

Yes, it looks that you have thought about it.
I suggest you to use the code to read the length below.
final int length = Integer.parseInt (scan.nextLine ());

Tags: Java

Similar Questions

  • Codec initialization problem!

    Hello

    I'm trying to use Adobe Media Encoder CS6 to convert a mov file to size 3072 by 768 resolution f4v to the same attributes.

    However, I get the error Codec initialization problem!.

    I can convert f4v 1920 x 1080 or other lower resolutions.

    Help, please.
    Thank you

    I am able to export 3072 x 768 to F4V, if I set the profile: high and level: 5.1

  • foreign key ALTER TABLE QUERY PROBLEM

    HAI ALL,

    ANY SUGGESTION PLEASE?

    UNDER: foreign key ALTER TABLE QUERY PROBLEM

    I want TO CREATE AND ALTER TABLE foreign key:

    1.TABLE:HAEMATOLOGY1
    COLUMN: HMTLY_PATIENT_NUM
    WITH
    TABLE: PATIENTS_MASTER1
    COLUMN: PATIENT_NUM (THIS IS THE KEY PRIMARY AND UNIQUE)

    1.TABLE:HAEMATOLOGY1
    COLUMN: HMTLY_TEST_NAME
    WITH
    TABLE: TESTS_MASTER1
    COLUMN: TEST_NAME ((C'EST LA CLÉ UNIQUE))
    ---------------


    SQL + QUERY DATA:
    -----------
    ALTER TABLE HAEMATOLOGY1
    Key constraint SYS_C002742_1 foreign (HMTLY_PATIENT_NUM)
    references PATIENTS_MASTER1 (PATIENT_NUM);

    ERROR on line 2:
    ORA-01735: invalid option of ALTER TABLE

    NOTE: THE NAME OF THE CONSTRAINTS: SYS_C002742_1 TAKEN FROM ORACLE ENTP TABLE DETAILS. MGR.
    ---------
    ALTER TABLE HAEMATOLOGY1
    Key constraint SYS_C002735_1 foreign (HMTLY_TEST_NAME)
    references TESTS_MASTER1 (TEST_NAME);

    ERROR on line 2:
    ORA-01735: invalid option of ALTER TABLE

    NOTE: THE NAME OF THE CONSTRAINTS: SYS_C002735_1 TAKEN FROM ORACLE ENTP TABLE DETAILS. MGR.

    ==============

    4 TABLES OF LABORATORY CLINIC FOR DATA ENTRY AND GET REPORT ONLY FOR THE TESTS CARRIED OUT FOR PARTICULAR

    PATIENT.

    TABLE1:PATIENTS_MASTER1
    COLUMNS: PATIENT_NUM, PATIENT_NAME,

    VALUES:
    PATIENT_NUM
    1
    2
    3
    4
    PATIENT_NAME
    BENAMER
    GIROT
    KKKK
    PPPP
    ---------------
    TABLE2:TESTS_MASTER1
    COLUMNS: TEST_NUM, TEST_NAME

    VALUES:
    TEST_NUM
    1
    2
    TEST_NAME
    HEMATOLOGY
    DIFFERENTIAL LEUKOCYTE COUNT
    -------------

    TABLE3:HAEMATOLOGY1
    COLUMNS:
    HMTLY_NUM, HMTLY_PATIENT_NUM, HMTLY_TEST_NAME, HMTLY_RBC_VALUE, HMTLY_RBC_NORMAL_VALUE

    VALUES:
    HMTLY_NUM
    1
    2
    HMTLY_PATIENT_NUM
    1
    3
    MTLY_TEST_NAME
    HEMATOLOGY
    HEMATOLOGY
    HMTLY_RBC_VALUE
    5
    4
    HMTLY_RBC_NORMAL_VALUE
    4.6 - 6.0
    4.6 - 6.0
    ------------

    TABLE4:DIFFERENTIAL_LEUCOCYTE_COUNT1
    COLUMNS: DLC_NUM, DLC_PATIENT_NUM, DLC_TEST_NAME, DLC_POLYMORPHS_VALUE, DLC_POLYMORPHS_

    NORMAL_VALUE,

    VALUES:
    DLC_NUM
    1
    2
    DLC_PATIENT_NUM
    2
    3
    DLC_TEST_NAME
    DIFFERENTIAL LEUKOCYTE COUNT
    DIFFERENTIAL LEUKOCYTE COUNT
    DLC_POLYMORPHS_VALUE
    42
    60
    DLC_POLYMORPHS_NORMAL_VALUE
    40-65
    40-65
    -----------------


    Thank you
    RCS
    E-mail:[email protected]
    --------

    ALTER TABLE HAEMATOLOGY1
    ADD Key constraint SYS_C002742_1 foreign (HMTLY_PATIENT_NUM)
    references PATIENTS_MASTER1 (PATIENT_NUM);

  • initialization problem multiple serial

    Hello all

    I have attached a vi that gives me a problem I cannot solve and would appreciate any help.

    The vi is supposed to intialise up to 7 ports series (only using 5 at the moment), and I guess that's a plausible way to do initialization (maybe wrong). The serial ports are connected to a pc via a usb hub. The windows XP operating system recognizes the Device Manager ports.

    The problem is that when the vi is executed, the following error is reported as shown in the word document attached.

    I compared the port settings in the properties in Device Manager for each port to the vi settings, and they match. What can we do?

    If anyone has a configuration with several serial ports could try the vi and see if it works for them?

    Thank you and best regards

    Ray

    It has nothing to do with several serial ports.  This has to do with an invalid parameter, you are trying to use it to configure one of the serial ports.

    Look at the information in the error message.  Point 4 of the property node to configure Serial Port VI is the setting of Stop Bits.  I see a point of stress goes in this VI, then that tells me the type of data in performing connections does not quite.

    You have an array of values of I32 and your values are made up of 1.  Disconnect this table and right-click on the terminal to configure Serial Port VI and choose Create Constant.  You'll see you get a data type of ring.  It's a U16.  But if you look at the items in there, you will see that the stop bits 1.0 has a value of 10.  1.5 has a value of 15, 2.0 has a value of 20.  If the value of 1 has no meaning to this property node and you get an error.  You should be wiring in a value of 10.

    Delete this table.  Create a table of constants in the ring.  Turn it into a control, and then choose the value of the correct ring for each item in your table.

    You have several other points of constraint.  They may not cause problems, but I consider disconnect them, create a constant of the correct data type and that using the table that you wire to configure Subvi.

    I have modified your VI and attached to it.  See if it works for you.

  • Testo 176 - Serial initialization problem

    I'm trying to get the 176P 1 talk with labview Testo 2011.

    I downloaded the TestoToolbox and also got an update for German help with an installer of Toolbox2.exe.

    In any case I can't pass the initialization process with the tcddka.dll of the Testo (V1.2).

    I have a simple question: this device name feed to the Init procedure?

    (1) the name, you can see in devicemanager?  in my case "testo 175-176-2010"--> Exception occurred in tcddka: invalid DeviceName in testo init.vi series

    (2) give but: 'testo175-176-2010'--> me ' Exception occurred in tcddka: the device does not respond in the series init.vi testo ".

    (3) or the general "testo175-177" translates by "Exception occurred in tcddka: the device does not respond in the series init.vi testo".

    Seems that I put the COM port correctly!

    + testo software is able to connect with the device without problem.

    earliers messages on a Testo gas detector, I have seen characters added and changes made to the comsoft.cat file...?

    All suggestions are welcome!

    I managed to get this 'base software comfort' currently running on a computer at home and changed the mode of operation of 'Connect' to the "extent", see below the image

    This cannot be given with the Lee Version 5 software, you have V4 that I found on the Web site, but has received assistance in Germany.

    This solves the problem and now I can acquire the data of the device with the highest vi attached!

  • Initialization problem

    Hello

    This is my code:

    int main (int argc, char * argv [])
    {
    error int = 0;

    / * initialize and load resources * /.
    nullChk (InitCVIRTE (0, argv, 0));
    errChk (panelHandle = LoadPanel (0, "CVI GUI.uir", Panel));

    / * display of the control panel and run the user interface * /.
    errChk (DisplayPanel (panelHandle));
    errChk (RunUserInterface ());

    initialize everything
    if(cycle == 0) initialize (Panel);
    else ResetTextBox (Panel, tabPanel1_tbxSystemMessage_A, "not initialized");

    Error:
    / * Cleanup * /.
    If (panelHandle > 0)
    DiscardPanel (panelHandle);
    return 0;
    }

    Sub Initialize (int Panel)
    {

    srand (time (NULL));

    now activate timer
    SetCtrlAttribute (Panel, tabPanel1_tmrTIMER, ATTR_ENABLED, TRUE);

    } //END Initialize()

    I met 2 problems that I can't fix right now.  I use global variable 'cycle' as my number of cycles, with the initial value of 0.  'cycle' is incremented by 1 each time that ticks of the timer.  In the Main() code, when it is zero, I call my function Initialize().  However:

    1. the Inifitialize() function is never called.  The timer is never activated.

    2. the object referencing a problem.  This line:

    ResetTextBox (Panel, tabPanel1_tbxSystemMessage_A, "not initialized");

    has a problem with 'Panel' (a global object).  I try again with 'panelHandle', and always he fouls out.  Same thing with this line:

    SetCtrlAttribute (Panel, tabPanel1_tmrTIMER, ATTR_ENABLED, TRUE);

    The "jury" passed is incorrect if the timer is never activated, but I don't know what is right for him.  Anyone has an idea on how to fix it?

    I think I found the root of the problem.  These two lines:

    errChk (DisplayPanel (panelHandle));
    errChk (RunUserInterface ());

    bring up the user interface and the thread goes in.  Anything done on the user interface written after these two lines are not executed until the thread leaves the user interface.  The Timer object exists only in the UI thread.  Thus, anything done to the "jury" and the timer object must be within the UI thread.  I changed my code to get concrete results.  in any case, thank you so much Wolfgang.

  • The tabs in Word table display problem.

    When I select several lines in my Word table is 'all or nothing' will display the tabs apply to all lines.  Could not locate the problem.

    Thank you for visiting the Microsoft answers community.

    The question you have posted is related to Microsoft Word and would be better suited in the Group Discussion in Microsoft Word. Please visit this link to find a community that will provide the support you want.

    Lisa
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • Customers table WRT54GS problem

    After Update v.5 WRT54GS with the construction of the 1.57.7 firmware 013 dated July 27, 2009 (and a router of the reconstruction after the reset procedure) I find that the customers table is empty or incomplete. I would like to know my equipment local IP addresses, once they negotiate a DHCP lease with the router. Someone can tell me why this is happening and is there a solution? (Everything on the LAN seems to be communicating OK, even if it is not listed in the Active IP Table.) Thank you.

    All seven devices are configured for DHCP. Strangely, in the last 24 hours, I've seen the devices appear in the table customers, one at a time. Now, they're all here. It's as if the old leases were to expire until they stood again. Maybe they have been reassigned new IPs, I don't know... in any case, the problem solved itself. Thanks for the reply.

  • 12 c: table scrolling problem?

    Hello!

    I am facing a strange probleam after migrating my application to 12 c (12.1.2.0.0). All the scrolling tables are too slow when the cursor point is on the contents of the table, but if the cursor is above the scroll bar, the speed is very good.

    PS. : Chrome scrolling is fine, just to IE10 and Firefox are slow.

    THX,

    Alexandre Rocco.

    Finally I managed to solve this problem

    I just added! important' CSS property, so this will overwrite the style that has been defined in the HTML code

    AF | : the table-body {} data

    position: static! important;

    }

  • EJB initialization problem

    Hi all

    I've migrated EJB 2.1, EJB 3 in my JSF project and facing a few problems during initialization by annotations.


    My JSF Managed Bean 1
    @ManagedBean(name = "mybean1")
    @RequestScoped
    public class MyBean1 { 
         public MyBean1 () { 
              super(); 
         }
    
         private String defaultTab = "";
         
            @EJB(name = "MyEJB") 
            private MyEJB myEJB;
    
         @javax.annotation.PostConstruct 
         public void init() {
              defaultTab = myEJB.retrieveDefaultOption(); 
         }
         
         public String loadDetail() {
              System.out.println("defaultTab::"+defaultTab);
              return "detail";
         }
    }
    My JSF Managed Bean 2
    @ManagedBean(name = "mybean2")
    @SessionScoped
    public class MyBean2 { 
         public MyBean2 () { 
              super(); 
         }
    
         public String showDetailForTracking() {
              MyBean1 myBean1 = new MyBean1();
              myBean1.loadDetail(); // Always prints defaultTab::     
              return null;
         }
    }
    When the loadDetail at 1 bean method is called bean 2 as shown in the snippet above, the default tab value is always "' as the EJB is not being built.

    Is there a way to solve this problem. Any suspicion on this would be much appreciated.

    Thank you.

    Think about it: you build MyBean instance yourself. Why do you want that the container to inject magically reference EJB in it then?

    Good mechanics JSF allows to inject the instance MyBean1 MyBean2! JSF 2 any book or article would have told you how. You can use the ManagedProperty JSF annotation:

      @ManagedProperty(value="#{mybean1}")
      private MyBean1 myBean1;
    

    or if you're on a JEE 6 container you can invest time in research on how to use the Commission for not only one model standardized injection.

    And a final tip: you make your life unnecessarily difficult by substituting the names of the default bean.

  • ADF: Columns of the Table filtering problem

    Hello

    My Version of JDeveloper is 11.1.1.5

    I am facing a problem with the filter of the table...

    Is it possible to implement the feature of research on filtering only on af:table with panelCollection?

    Could someone help me please in this?

    I need Research* not only the filtering of the data inside the table with the facet of the columns of the table filter...

    Can someone help me with this application?

    Many thanks in advance,

    Kind regards
    Anil

    Published by: 977652 on February 17, 2013 19:28

    Published by: 977652 on February 17, 2013 19:38

    You can just type in the filter like '% EBS' field and you will find your file.

    Timo

  • AE expressions - linking text to a table (syntax problem) external text layer

    Hi all

    I am struggleing to solve this problem-any help would be greatly appreciated.

    In a text outside the legacy document, I have some pictures saved as follows:

    var = Los Angeles ['Los Angeles', "city Type:", 'Multi City', "Geo:", '-115.180664062,36.111252521', "languages:", "31", "County of POI: ', '20'," County Photo: ', '600', 'Video', 'Y', 'Video views', '30 200'];

    var Las_Vegas = ['Los Vegas', "city Type:", 'Multi-City', "Geo:", '-118.243684900,34.052234200', "languages:", "29", "County of POI: ', '20', ' County Photo:", '331', 'Video', 'Y', 'Video views', '26 000'];

    var Sydney = ["Sydney", "city Type:", 'Multi-City', "Geo:", "151.204250000,-33.866850000", "languages:", "29", "County of POI: ', '20'," County Photo: ', '331', 'Video', 'Y', 'Video views', '26 000'];

    In my comp in AE, I have a layer of text called "city selector. The source text is retouching to navigate between table names (for example: "Los Angeles", "Las_Vegas").

    I then many other text layers, with the following expression in the parameter of source text-

    try {}

    myPath = ' / Volumes/VIdeo-Master/videos/find your project b0ss/source.txt ';

    $.evalFile (myPath);

    eval (thisComp.layer("CITY_PICKER").text.sourceText) [Math.round (effect ("Slider Control") ("Slider"))];

    } catch (err) {}

    "MISSING."

    }

    Each text layer has a slider control to call another element in the table. Thus simplified, the 4th line of the code should read-

    eval (arrayname) [number]

    For example: eval (Sydney) [5] must return ' language:'

    HOWEVER, instead, when

    eval (Sydney) [5] returns "y".

    eval (of Los Angeles) [5] returns ' no

    eval (of Los Angeles) [3] returns "_".

    Everyone can see what I'm doing wrong?

    See you soon!

    Hi again,

    I realize I completely misunderstaood the role of the SELECTOR of the CITY, where your question.

    Next, you need the eval. I'm sorry.

    In your original expression, try to replace eval (thisComp.layer("CITY_PICKER").text.sourceText) [...]

    by eval (thisComp.layer("CITY_PICKER").text.sourceText.value) [...]

    If my guess is rigth, AE expressions allow an amibiguities between the properties and their value, but eval (which is a native js function) does not work.

    Then your original expression begins with the assessment of a property should evaluate a string ("Sydney", etc...)

    Have not tried.

    Xavier

  • Table format problem - please help

    Here's what I'm trying to do:

    I have a set of documents in xml format according to the docbook standard.  In these documents, there are also types of table.  Standard TABLE with its tag element and an informal table with the tag of the INFORMALTABLE element.

    When they are open and my file format and ESD apply I want Standard tables to have a blue shadow header and informal boards have a shaded gray header.  I created the models of appropriate table.  I can't understand a way via ESD to specify the type of table format that works.  When I open an xml and apply the edd and the format of all tables to open it using the table format that appears first in the list.

    What can I do for ESD to reach my goal?

    Thanks in advance

    Russ,

    Thanks for letting me know my messages were getting through. I just responded to the original rather than through the interfaces forums and had no idea there was a problem. I tried to post twice on this topic today:

    The messages were:

    Russ,

    You are right. A DSP can specify an initial table format. The word "initial" is the key. This is the format that is used when a new table is created, if the new table is created interactively by the user or by opening a SGML or XML document. Initial table layouts do not affect the existing tables. In fact, for a table created in interactive mode, the initial table format determines the format that is highlighted when the Insert Table dialog first. The user is free to choose a different size if you wish.

    and

    Qualar,

    R/w rules are not sensitive to the context, so that if you use an FM tgroup element, they will not be able to help. Tgroup in your EDD definition can define a format of original table of Format if the tgroup is within the item table and Format B if the tgroup lies in informaltable. Just make sure that you have imported ESD in the model before you open the XML document. As you have noticed, if you open the XML document and then import the EDD, the tables already exist and that their format is not affected.

    -Lynne

  • Advanced table navigation problem

    Hello

    I have a table points to a page that shows the 10 records per page . Next and previous links of advanced table are used to access to other records. Action table-> single selection is enabled on the advanced table. There is also a button called * "View history" * in advanced table actions. After you select a record in the advanced table and clicking on the button view history, a new history of page B is displayed. Story page button named back there. The URI of Destination of the back button property is the URL of the original page B. When click on the back button, the original page A is displayed.

    Now, if say I browse to folder of 21-30 of advanced table by clicking on the link next to the advanced table. I selects the 25 record and click View history. Coming up on page B. I click the back button and now it displays A page, but the problem is the displayed records in the advanced table are from the beginning it i.e. it displays the top 10 records. The requirement is that when I come back to page A, advanced table should display (20-30) records that I chose to view the history during the click on the back button.

    I would like to know how to solve this problem.

    Thank you
    VG

    Hey Vg,

    When you leave the page to view the history, get the VO rangeStart and rangeSize and pass them as parameters to the history page. When we click on the back button pass you those on A page as parameters. Then in your PR of A Page, you set the rangeState and the rangeSize of the VO to what passed as parameters.

    Keep the beginning and size.
    int savedRangeStart = vo.getRangeStart ();
    int savedRangeSize = vo.getRangeSize ();

    restore the rangeStart and rangeSize

    vo.setRangeSize (savedRangeSize);
    vo.setRangeStart (savedRangeStart);

    For more information, see Jdeveloper help search advanced tables.

    Kristofer Cruz

  • Table header problem

    In the form below, is there a way to have a single table header instead of a header above each dynamically generated unique row? I put the header line binding to a maximum of one (1), but he don't seem to have any effect. I want the header to disappear if the user deletes all the lines (removes with the last visible line).

    https://Acrobat.com/#d=Mmpq-vPoGUdJumXEcaG6Sg

    Thanks for any help that you can provide it.

    -Don

    Place the following code in the click event of the button "DeleteActionRow".

    var nResponse = xfa.host.messageBox ("you are about to delete this line of action point. \n\nDo you want to continue? ","deleting a line ", 1, 2);
    If (nResponse == 4) {}

    var oActionSubform = MeetingMinutes.LogoControls.resolveNode ("ActionSubform [" + this.parent.parent.parent.index + "]");
    var intCount = oActionSubform.Table1.Row2.instanceManager.count;
     
    oActionSubform.Table1.Row2.instanceManager.removeInstance (this.parent.index);

    {if(intCount==1)}
    oActionSubform.Table1.HeaderA.presence = 'hidden ';
    }
       
    If (xfa.host.version< 8)="">
    XFA. Form.Recalculate (1);
    }
    }

    Place the following code in the Initialize event of the button "DeleteActionRow". »

    var oActionSubform = MeetingMinutes.LogoControls.resolveNode ("ActionSubform [" + this.parent.parent.parent.index + "]");

    {if(this.parent.instanceManager.Count>0)}

    oActionSubform.TopicGroupA.Table1.HeaderA.presence = "visible";

    }

    Thank you

    Srini

Maybe you are looking for