Results 1 to 2 of 2
  1. #1
    xlactyu is offline Member
    Join Date
    Oct 2014
    Posts
    9
    Rep Power
    0

    Default How to write a JAVA program that reads a whole number and tells you the decimal place

    Ex. If I type 5943, the program will say

    mill = 5

    hun = 9

    ten = 4

    uni = 3

    I hope you get the picture I had to translate the decimal value names from a different language.

    This is what I have tried...,
    Java Code:
    import java.util.Scanner;//Permite el uso de leer el teclado del usuario
    
    public class DeterminarValorDecimal//Nombra el documento
    {
    
       public static void main(String [] args)//Podemos ver la clase
       {
       
          Scanner input = new Scanner( System.in );//Provee la herramienta para leer el teclado de el usuario
          
          int nument1,//Declaracion de variable
              nument2,
              nument3,
              nument4;
          
              
              
          System.out.print( "Entre un numero de el 0 al 9 " );
          nument1 = input.nextInt();
          System.out.print( "Entre un numero de el 0 al 9 " );
          nument2 = input.nextInt();
          System.out.print( "Entre un numero de el 0 al 9 " );
          nument3 = input.nextInt();
          System.out.print( "Entre un numero de el 0 al 9 " );
          nument4 = input.nextInt();
          System.out.println(nument1 + " Millares " + nument2 + " Centenas " + nument3 + " Decenas " + nument4 + " Unidades ");
       }=
    }
    But what this does is I have to enter the single digits one by one. I want to be able to type the whole number. Is there a method that reads the length of the whole number and lets me classify each digit so I can do what I want to do?
    Last edited by xlactyu; 10-10-2014 at 07:41 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: How to write a JAVA program that reads a whole number and tells you the decimal p

    If you read the number as a String, the String class has methods you can use to get the single digits in the String.

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 11
    Last Post: 06-23-2013, 05:43 PM
  2. Replies: 2
    Last Post: 10-06-2012, 05:29 AM
  3. Replies: 7
    Last Post: 11-30-2011, 07:58 PM
  4. Write a Program that reads two times in military format
    By HPcompaq256 in forum New To Java
    Replies: 10
    Last Post: 02-26-2010, 05:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •