Separating user-entered int into digits

For example, if the user enters "123", separate it to 1, 2, 3. I've tried converting the int to a String and using charAt, and I've tried dividing: %10 and /10.
Here is my current charAt attempt:
public static void main(String[] args) {
          Scanner keyboard = new Scanner(System.in);
          System.out.print("What is the number? " );
          int num = keyboard.nextInt();
          String numString = String.valueOf(num);
        int numLength = numString.length();
      while (numLength >= 1) {
        int dig = (numString.charAt(numLength)) - 48;
          System.out.println(dig);
        int newNumLength = numLength --;
        dig = (numString.charAt(newNumLength)) - 48 ;
        System.out.println(dig);}
     }I was using - 48 because at first it was working for getting the first digit in the int.

If your String is "123", then your first character is '1', and you just want to print out the '1'. There's no need for the -48 part.
Try this:
int i1 = 48;
int i2 = '0';
System.out.println(i1);
System.out.println(i2);
char c1 = 48;
char c2 = '0';
System.out.println(c1);
System.out.println(c2);Edited by: jverd on Apr 11, 2011 5:18 PM
Edited by: jverd on Apr 11, 2011 5:19 PM

Similar Messages

  • Can a form user enter pictures into a pdf?

    Just a new user... I want my inspectors to be able to insert pictures into a description line.  Is this possible?

    As Kevin suggested it is totally Customization.
    In OIM first time while setting QA it brings the question from Lookup but after that it reads from the PCQ table only.
    So as you want that User should be able to set his own Questions then no need of any Lookup *(APMK)*. You can build your custom JSP to enter Questions as well as Answers and send these data to PCQ table. It should be in Encrypted Format.
    Next time when User Logs in it wil fetch the questions from PCQ table and validate the answers from that. So no need of Question Lookup.
    Question Lookup we use because we want to show same questions to everyone and it is configurable and we can change the questions as per client requirement.
    In your case your user are entering there own questions.

  • Dividin an Int into Digits

    Hey i a trying to divide an integer that i am reading from he keyboard
    IE: 459874
    into an array of integers
    int Array[]={4,5,9,8,7,4}
    Is there a native function in java that might allow me to do that? Or am i gona have to read into a string and then use the tokenizer?
    Any help is appreciated

    Is there a native function in java that might allowDo you really mean native? Or do you mean a java function that's part of the java standard package library
    me to do that? Or am i gona have to read into a
    string and then use the tokenizer?Yes you are going to have to do it yourself. But don't use a tokenizer. it's much simpler than that.

  • To compare two user entered dates

    HI FRIENDS
    here is my code. When i try to print the user entered date (dd/MM/yyyy)(which i am storing in a string) the program dispalys nothing. and everey time i enter a valid date it displas "invalid From date entered ". I need to store the user entered date into a string because i need that for further use. All my intesion is to get two dates from user in dd/MM/yyyy. Strore them in certain variable. Check if they are valid or not. and make sure todate is either equal or greater than fromdate. Please help me to solve this problem.
    public class EDTDateValidation extends JFrame implements ActionListener{
    private JLabel fromlabel;
    private JLabel tolabel;
    private JTextField fromtxt;
    private JTextField totxt;
    private String fmt ="dd/MM/yyyy";
    private java.lang.String fromdate;
    private java.lang.String todate;
    private JButton buttonOK;
    private JButton buttonCancel;
    private Date theDate;
    private Date date1;
    private Date date2;
    private JPanel mainPanel;
    SimpleDateFormat dtformat = new SimpleDateFormat(fmt);
    public EDTDateValidation(){
    super("Date Validation");
    dtformat.setLenient(false);
    mainPanel=new JPanel();
    mainPanel.setLayout(null);
    fromlabel = new JLabel("From Date");
    tolabel = new JLabel("To Date");
    buttonOK = new JButton("OK");
    buttonCancel = new JButton("Cancel");
    fromdate = new String();
    todate = new String();
    fromtxt = new JTextField(10);
    totxt = new JTextField(10);
    fromdate = fromtxt.getText();
    todate = totxt.getText();
    mainPanel.add(fromlabel);
    fromlabel.setBounds(20,20,50,15);
    mainPanel.add(tolabel);
    tolabel.setBounds(20,50,50,15);
    mainPanel.add(fromtxt);
    fromtxt.setBounds(90,20,130,20);
    mainPanel.add(totxt);
    totxt. setBounds(90,50,130,20);
    mainPanel.add(buttonOK);
    buttonOK.setBounds(70,80,71,23);
    mainPanel.add(buttonCancel);
    buttonCancel.setBounds(150,80,71,23);
    buttonOK.addActionListener(this);
    buttonCancel.addActionListener(this);
    setContentPane(mainPanel);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(247,140);
    setResizable(false);
    //pack();
    public static void main(String args[]) {
    try {
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    catch(Exception e) {
    System.err.println("Could not load Look and Feel" + e);
    EDTDateValidation edtDateVal = new EDTDateValidation();
    edtDateVal.setVisible(true);
    public void actionPerformed(ActionEvent e) {
    if(e.getSource() == buttonOK){
    System.out.println(fromtxt.getText());
    // System.out.println(SimpleDateFormat.format(fromdate));
    System.out.println(fromdate); //THIS DISPLAYS BLANK
    System.out.println(todate); //THIS ASWELL
    try {
    Date date = null;
    date = dtformat.parse(fromdate);
    System.out.println("valid From date entered!");
    catch(Exception f) {
    System.out.println("Invalid From date entered!");
    // textField1.setText("");
    return;
    try {
    Date date = null;
    date = dtformat.parse(todate);
    System.out.println("valid TO date entered!");
    catch(Exception f) {
    System.out.println("Invalid To date entered!");
    // textField1.setText("");
    return;
    }

    Judging from your code, you've got a lot of learning
    to do. I suggest you
    split it up:
    1. Write non-GUI code that attempts to parse, compare
    and format dates.
    2. Write simpler GUI code to capture ordinary
    strings, for example, and
    worry about dates after you can do something simpler.And standard instructions: Use code tags.

  • If I get a user to enter their name as a variable and I am linking one movie to another using a button, is there a way to carry the user name forward into the second movie?

    If I get a user to enter their name as a variable and I am linking one movie to another using a button, is there a way to carry the user name forward into the second movie?

    Hi there
    See if the link below helps
    Click here
    Cheers... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • I entered my download digital copy into itunes, it is in my purchase history, but not in my itunes

    I entered my download digital copy into itunes, it is in my purchase history, but not in my itunes. Help

    Audiobooks (and ringtones) are currently a one-time only download from the store. If you don't have it on a backup of your downloads then you can try contacting iTunes support and see if they will grant you a re-download : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • Allowing users to enter text into a web page

    Hi there,
    I'm not at all versed in Java, so I would like some advice on how to do the following in a web page.
    Imagine you have a group of four users and they have to be able to give you a response to a question and be able to see what the others have responded.
    Basically I want the users to be able to to enter text into the webpage, so that the question can be changed and also so that each person can change their reply (in a space under their name.)
    It would also be acceptable if the text was from a predetermined list, ie a drop down list which has a "memory"
    Any ideas would be most welcome, thanks in advance!
    -Ekipero-

    Hi again,
    I think I didn't explain myself clearly enough.
    Basically, all I need is a text box which can be edited by anyone who visits the webpage, and which once edited has a "memory" so the next person who visits the page can see what the person before wrote.
    I don't know any Java but I'm sure an applet to do this can't be too difficult right?
    Perhaps doing it through a text box and a Submit button which then pastes what has been written in the text box onto the page? Or perhaps the text can be chosen from a predetermined list?
    Thanks in advance to all ;-)
    -Ekipero-

  • Two fields, two scripts. User can enter data into field 1 or 2

    Hi all,
    New here, and to acrobat forms, so please bear with me!
    What I'm trying to achieve is a form that calculates total invoice value, based on a total number of hours worked, and a rate. The user fills in the total hours, but then the problem is that some people know their fixed rate, and others have a changing rate. Those with a changing rate simply know the amount they are invoicing for. What I'd like, is a way for the TotalInvoice value to be calculated by Rate*TotalHours when the user enters a value into the Rate field... OR ... for Rate to be calculated by TotalInvoice/TotalHours when the user enters a value into the TotalInvoice field.
    I can make it go one way or the other (so the script is only in TotalInvoice field or the Rate field), but I can't manage to get it to go both ways. Is this possible?
    To summarise: User can enter manually into Field1 and value of Field2 is calculated, or user can enter manually into Field2 and Field1 is calculated.
    Thanks!

    What you propose can be difficult, becuase you're describing a circular reference between the two fields. When the 1st value changes, you want the 2nd value to be calculated based on the 1st value. But when the 2nd value changes, you want the 1st value to be calculated based on the 2nd, ad infinitum. There are ways to short-circuit the loop, but it depends on whether you need to do the calculation only when there is manual entry, or whether you need it to work when either field value changes programmatically or by importing form data.
    Sometimes it's just easier to have the user press a button to calculate and set the other field value.

  • Today's date dynamically entered into text field that user enters additional text into same field.

    Trying to have today's date dynamically entered into a repeating table row textfield when the button is clicked to create each repeating row. The user can then enter addtional text into the same text field next to the date.
    Example:
    [4/25/2012] This is the text the user entered.
    Today's date is populated in each update row created when the "Update Row" button is clicked.
    The following script works but only for the first instance, not the second, third, forth, etc...
    Click event: (JavaScript, client)
    this.resolveNode('Table2._RowB').addInstance(1);
    xfa.resolveNode("Table2.RowB.#subform.Update").rawValue
    Thank you,
    ~Don

    Hi Don,
    Does this solution cover the above problem? https://acrobat.com/#d=VjJ-YsXLKmV6QU84JrAAIw
    Niall

  • Entering numbers into textfield

    Hi,
    is there any way of entering numbers into a textfield whereby the user doesn't have to toggel the device inorder to produce said numbers- a bit like a calculator application; any suggestions welcome
    James

    Sure, it is very easy.
    Read about TextField Input Constraints.
    They are
    ANY
    EMAILADDR
    NUMERIC
    PHONENUMBER
    URL
    DECIMALYou need NUMERIC or DECIMAL.
    You can set them in two way
    1. public void setConstraints(int constraints)2. Pass to TextField constructor:
    TextField(String label, String text, int maxSize, int constraints)e.g.
    TextField myTextField = new TextField("myLabel", "myText", 32, TextField.NUMERIC)Read also about Input Modes. It can be also useful.

  • How can I read the last cell of a JTable that a user Enters data

    I have a one column JTable with several rows that a user enters data to. Upon entering the last data, the user clicks a button to read all the data from the rows in the JTable and puts them in an arraylist. If the user does not click enter or navigates away from the last cell, then after clicking the button it does not read the last cell entered. Since the user is clicking on a button to indicate he is done entering data on the table, does he also have to hit the enter key to indicate he is done entering the data?
    The code below is my tablemodelListener:
    public class InteractiveTableModelListener implements TableModelListener {
    public void tableChanged(TableModelEvent evt) {
    if (evt.getType() == TableModelEvent.UPDATE) {
    int row = evt.getFirstRow();
    System.out.println("Update row:"+" "+row);
    jTable1.setRowSelectionInterval(row, row);
    }

    Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
    In the future, Swing related questions should be posted in the Swing fourm. (This question has been asked and answered dozens of times).
    But there is not need to repost because [Table Stop Editing|http://www.camick.com/java/blog.html?name=table-stop-editing] explains whats happening and give a couple of solutions.

  • Propagating users/Groups/Roles into partner application

    I am very newbee to portal development. I have a following need.
    I want to use Single SingOn feature of Portal. Once the user logged in to the portal via SSo, there may be several applications(within the portal) to which S/He may have access to. Based on who S/He is, may have different level of authorization to what S/He can do into different applications within the portal. How I can make use of user entered for Single Signon, propagate to the application level inside the portal.
    My understanding so far with the portal is that you can develop a portal which has web clipping portlets, external/internal applications, items etc. When we create the users and groups and assign roles to the users, it is limited to the portal front page that we publish to public.
    My problem is further down, into different applications which I expose with the help of portlet or by any other means. And have control over in that particular application(individual), which portion of the application users should be able to see or take any action.
    Your help is highly appreciated.

    Any one has a clue?

  • Can you create a user entered text field that flows content in a subform?

    I am working on a conversion project taking a document library of over 600 forms from Word into PDF, for the most part it's simple and binding fields to the database schema and using subforms is working quite well - however, there are some instances where there is a combination of user entered fields mixed with database fields and in some cases the end user fields are all there are but the amount of content can vary from 250 characters to thousands.  The project manager wants a PDF that enables users to enter whatever amount of text they need to and have the form layout function the way it does as if all fields were populated by the database - I don't know of a way to make that work unless content is entered in the schema first (or implement CM and have all users working in LiveCycle, but the database uses PDF, sothat's not an option right now).
    If anyone has any ideas how to make these things work I would greatly appreciate hearing about it.
    Thank you so much,
    R

    Hi,
        If you can post your form in the post, I can have a look at it and provide my feedback.
        I created a sample file for your reference..
        1) The Content property for the Page1 was set to Flowed.
        2) Each text box is placed inside a Subform which is also has the content property set to Flowed.
        3) In the Form Properties, under the Default tab, set the PDF render format as Dynamic XML form.
        4) In the Form Properties, under the Preview tab, set the Preview Type as "Interactive Form" and Preview Adobe XML Form as "Dynamic XML form". (this step is for the previewing the PDF in the designer).
        5) Finally save the form as Dynamic XML form. (File Menu -> Save As).
    Hope this helps.
    If you still have issues, please post your form..
    Thanks
    Srini
    Please find the sample file at the below location
    https://acrobat.com/#d=qQohvZGsJrky-sTdPTJbzA

  • How can I get my wireless keyboard and my new magic mouse to enter info into a Christmas list app on iphone 3GS? Do I have to move to another room? I have bluetooth on in my iPhone.

    I have wireless keyboard and a new magic mouse. I want to enter data into a Christmas list app on my 3GS iPhone. Too time consuming to just type on iPhone keyboard. How can I get keyboard and mouse to be 'connected' or recognized by my iPhone? I have Bluetooth "on" in my iPhone.

    You cannot connect the mouse.  This is not a feature of iphone
    You can learn about connecting a keyboard in the manual:
    iPhone User Guide (For iOS 5.0 Software)

  • User-entered field treated as read-only

    I created a large form in version 7. I brought it into version 8 to work on it some more. I believe this may be related to going from 7 to 8...
    I have lots of numeric fields in rows and columns. All the fields are User Entered - Optional. When I view it in Preview, one field in the middle will not allow entry. It's as if the field were Read Only. I go back to Design mode and the field is still listed as User Entered. This occurs on a few pages.
    Anyone else had this problem? Any suggestions?

    My office uses Times New Roman as a standard font for all our forms, I dragged several of the most used standard objects into a blank form, altered them to fit our standards and then dragged them back into the standard tab. Much easier than going through the process each and every time you need to pull a field in, fyi. You can also put a script into a field and put it into either the custom tab or create your own tab for personal objects, I find this saves me huge time by not having to re-type scripts over and over.

Maybe you are looking for

  • Error in version 2.1.1

    I installed the new version and got an error under the new tab 'Sensors': Oracle BPEL Process Manager Full Cycle An unexpected error has occurred while executing your request. This is most likely related to a defect in the Oracle BPEL Process Manager

  • What cable to connect the fa0/0 port on a router to the fa0/0 switch port

    i don't know if i know this question, but i got it in the exam recently and i chose - straight-through cable. please is this right? if not then what is the right cable to use?

  • Expand all/ Collapse all topics button and Visited Topics color

    Hi First of all, I am not sure if it is a good idea to create one post for two queries. But I have these two requirements for my project. 1. I need a Expand all/ Collapse all button(s) on the toolbar, which will open and close all books in the ToC. I

  • Cycling issue in DVD Menu

    I have the DVD Menu looping at 15 seconds. At the end of the 15 seconds, the button dissapears for like half a second and reapppears... I was wondering if there is a way to eliminate the choppiness as the DVD Menu recycles. Advice would be greatly ap

  • Disable iTunes auto launch on iPhone docking.

    Hello I'm trying to disable iTunes from automatically opening when I dock my iPhone to my computer. I have successfully done this by disabling ituneshelper.exe but this automatically enables itself after every reboot. (even if I disable it via msconf