Please give me coding for this..

Please give me coding for this..

Write an application that inputs one number consisting of five digits from the user.separates the number ibto its individual digits and prints the digits separated from one another by three spaces each.For Example.if the user types the number 42339,the program should print

4 2 3 3 9

Assume that the user enters the correct number of digits.What happens when you execute the program and type a number with more than five digits??What happens when you execute the program and type a number with fewer than five digits??

View Answers

March 1, 2011 at 4:02 PM

Java separate digits by space

import java.util.*;
class   AddSpaceToDigits
{
    public static String addSpaceToRight(String s, int n) {
     return String.format("%1$-" + n + "s", s);  
}

public static void main(String args[]) throws Exception {
    Scanner  input=new Scanner(System.in);
    System.out.print("Enter number: ");
    int num=input.nextInt();
    String st=Integer.toString(num);
    String digit[]=st.split("");
    System.out.print(digit[0]);
    for(int i=1;i<digit.length;i++){
    System.out.print(addSpaceToRight(digit[i], 3));
    }
    System.out.println();
}
}

March 6, 2011 at 4:29 PM

sry i dnt knw arrays yet...i want to solve this from any function...

42339/10000=4.2339take 4 from this









Related Tutorials/Questions & Answers:
Please give me coding for this..
Please give me coding for this..  Write an application that inputs one number consisting of five digits from the user.separates the number ibto its individual digits and prints the digits separated from one another by three
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that prompts the user to enter the number of students and each studentâ??s name and score, and finally displays the name of the students
Advertisements
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that reads in investment amount, annual interest rate, and number of years, and displays the future investment value using the following formula
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a program that displays the following table (note that 1 mile is 1.609 kilometers). Miles Kilometers
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Suppose that the tuition for a university is RM10,000 this year and increases 5% every year. Write a program that computes the tuition in ten years and the total cost
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a function called ChangeToNext that take in an uppercase character parameter ch. The function returns the next uppercase character if ch is between 'A' and 'Y
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Write a class that contains the following two methods: /* converts from inches to centimeters */ Public static double inchToCentimeter(double in) /* converts from
hi.. please give me a java coding for the following question
hi.. please give me a java coding for the following question  Body Mass Index(BMI) is a measure of health on weight. It can be calculated by taking your weight in kilograms and dividing by the square of your height in meters
Please give me the answer.
"int a=08 or 09" its giving compile time error why   "int a=08 or 09" its giving compile time error why ? can any one give me the answer of this please
Begineer in coding please help me
Begineer in coding please help me  I have Person class{ int pid; String Pname; //and have a Address filed of type Address not String!!! Address... address to a person object.. please help me
please give me an idea to develop a program for this question?
please give me an idea to develop a program for this question?  How to enter a text or number from keyboard without using InputStreamReader method in java
please help me to give code - Java Beginners
please help me to give code  Write a function with a signature cheerlead(word) that prints a typical cheer as follows. The word robot: Gimme an R Gimme an O Gimme a B Gimme an O Gimme a T What did you give me? ROBOT
please help me to give code - Java Beginners
please help me to give code  Write a function, sliding(word, num)that behaves as follows. It should print out each slice of the original word having length num, aligned vertically as shown below. A call to sliding(examples, 4
problem in writing coding. Please help me.
problem in writing coding. Please help me.  Hi sir, my name is Logeswaran. I have problem in writing JSP coding for my university assigments... like? I'm really stuck on this. Please help me. By the way, I'm using Access
please help me to give code - Java Beginners
please help me to give code  Write a program that prints an n-level stair case made of text. The user should choose the text character and the number of stairs in the stair case * ** *** ****   Hi friend
please help me to give code - Java Beginners
please help me to give code  Write a program that uses loops to generate an n x n times table. The program should get n from the user. As a model here is a 4 x4 version: | 1 2 3 4
please help me to give code - Java Beginners
please help me to give code  Write a program that reads a file named famous.txt and prints out the line with the longest length. In the case of a tie, you may print out only one of them. For example in the file: Alan Turing
please help me in coding this given program
please help me in coding this given program  consider the below series: 1,2,1,3,2,5,3,7,5,11,8,13,13,17,..... this series is a mixture of 2 series... in this series. (i m unable to code this program..please provide solution
please help me in coding this given program
please help me in coding this given program  consider the below series: 1,2,1,3,2,5,3,7,5,11,8,13,13,17,..... this series is a mixture of 2 series... in this series. (i m unable to code this program..please provide solution
please give me a java program for the following question
please give me a java program for the following question  Write a java program that displays multiple frames : Step 1: Design a frame with three buttons: ?Fruit?, ?Bird? and ?Animal? Step 2: On clicking ?Fruit? button
hi... pls give me the example of java coding fo following question
hi... pls give me the example of java coding fo following question  example java coding that reads in the radius and length of cylinder and computes volume. formula: Area = radius * radius * PI Volume = area * length
how to send email please give me details with code in jsp,servlet
how to send email please give me details with code in jsp,servlet  how to send email please give me details with code in jsp,servlet
please give me an example about shopping cart using spring and hibernate
please give me an example about shopping cart using spring and hibernate  who can give me an ex about shoppingcart using spring and hibernate intergration ? thanks alot
hi... pls give me the example of java coding for following question
hi... pls give me the example of java coding for following question   Write a program that computes loan payments. The loan can be a car loan, a student loan, or a home mortgage loan. The program lets the user enter the interest
hi... pls give me the example of java coding fo following question
hi... pls give me the example of java coding fo following question  Write a java program that reads the following information and prints a payroll statement: Employeeâ??s name (e.g: Sam) Number of hours worked in a week (e.g: 10
hello sir, please give me answer - Java Beginners
hello sir, please give me answer  Write a program in Java that calculates the sum of digits of an input number, prints... ways in java? so , sir please tell me full solution of this program   Here is your complete
Hi Every One , please give me some idia to opning audio File . please Help ..
Hi Every One , please give me some idia to opning audio File . please Help ..  hi Dear Friend , please give me a program to opening audio file... me .please Help
Please give me the code for the below problem - Java Interview Questions
Please give me the code for the below problem  PROBLEM : SALES TAXES Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty is an additional sales tax
why and where we use setter and getter methods in java, please give me one example program.....
why and where we use setter and getter methods in java, please give me one example program.....  why and where we use setter and getter methods in java, please give me one example program
please give me solution how to display next page after 20 records ? - JSP-Servlet
please give me solution how to display next page after 20 records ?  Java Servlet Paging control example  here i have attached one example code. function validate() { for(j=0;j<30;j
Plz give java coding for this
Plz give java coding for this  ... iMin = 1, iMax = 8, iMid; // give max. value in even no. int jMin = 1, jMax = 12, jMid; // give max. value in even no. iMid = iMax / 2; jMid = jMax / 2
jsp coding please.
jsp coding please.  hi sir, my name is logeswaran. I have a problem... list. please show me how to do it? thank you. By the way, I'm using access database and coding JSP.   Follow these steps: 1)Go to the start->
plz give me answer
plz give me answer  Discuss & Give brief description about string class methods   Java string methods
Please help me to create this coding for pizza order application using a handheld computer.....
Please help me to create this coding for pizza order application using a handheld computer.....  You work as a programmer for IT-Tech a small... in the kitchen which displays the orders to be cooked. anybody please help me
plz give me answer
plz give me answer   description about string class methods   Java string methods
plz give me answer
plz give me answer   description about string class methods   Java string methods
plz give me answer
plz give me answer   description about string class methods   Java string methods
GIVE ME A ANSWER
GIVE ME A ANSWER  Discuss the Number Class in the java.lang package   Number class is an abstract class extended by all classes that represent numeric primitive types such as Byte, Short, Integer, Long, Float
Please provide the coding for this problem
Please provide the coding for this problem  Please provide the coding for the following problem. Write a "hangman" game that randomly generates a word and prompts the user to guess one letter at a time. Each letter in the word
give me a grid example in php
give me a grid example in php  give me easy code example of grid in php like mysql editor
please help me
please help me  Dear sir, I have a problem. How to write JSP coding, if a user select a value from drop down list for example department, the another... before. This name list should get from the database. Please help me. By the way, I'm
urgent...pleAse help me.....please!
urgent...pleAse help me.....please!  please help me urgent! how can i do dictionary with the use of array code in java, where i will type the word then the corresponding meaning for that word will appear...thanks
please help me to overcome this problem
please help me to overcome this problem  how to make it easy to write java code. can u please give me suggestions
tell me coding for this
tell me coding for this  Write an application that displays the integer equivalents of the following character...A   Java get Integer value of Character class GetIntValueOfCharacter { public static void main
please help me.
please help me.  Please send me a code of template in opencms and its procedure.so i can implement the code. Thanks trinath
please help me.
please help me.  How to read a properties file in java with a suitable example. Please send me. Thanks Trinath   Please visit the following link: Java read properties file
plz give me answer plz
plz give me answer plz  writw a programme to find rank from an array using doubledimmensionalarray
please help me.
please help me.  Please send me the validation of this below link. the link is http://www.roseindia.net/answers/viewqa/JSP-Servlet/9584-JSP-Servlet-Search-and-Edit.html Thanks Trinath
Plz give me code for this question
Plz give me code for this question  Program to find depth of the file in a directory and list all files those are having more number of parent directories
please tell me
please tell me  i have created one table,when i close and again login, table name will be there, but its content not displayed, showing as no rows selected, please tell me the reason

Ads