Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Help in writing a java application.
Closed Thread
Old 11-06-2006, 10:47 AM   #1 (permalink)
 
Banned

Join Date: Aug 2005

Posts: 3,480

maroon1 is on a distinguished road

Default Help in writing a java application.

Our programming teacher asked as to write a Java application for a problem in our book, but I didn't know how to write it. Please can someone help

this is the problem
Quote:
Write an application that inputs one number consisting of five digits from the user, separates the number into its individual digits and prints the digits separated from one another by three spaces each. For example, if the user types in the number 42339, the program should print
PHP Code:
4   2   3   3   9 

maroon1 is offline  
Old 11-06-2006, 11:02 AM   #2 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default

So what do you want help with? We're not going to do your homework for you. Start coding and when you run into a specific problem, post your code.
jaeusm is offline  
Old 11-06-2006, 11:48 AM   #3 (permalink)
 
Banned

Join Date: Aug 2005

Posts: 3,480

maroon1 is on a distinguished road

Default

Quote:
Originally posted by jaeusm
So what do you want help with? We're not going to do your homework for you. Start coding and when you run into a specific problem, post your code.
I'm noob in programming.

My problem is that I don't know how to separate the digits by three spaces

I have wrote this program


Quote:
import java.util.Scanner;

public class Digits

{ public static void main(String args[])

{

Scanner input=new Scanner(System.in);



int number;



number=input.nextInt();



System.out.printf("%d",number);

}
}
but this one ^^ doesn't display the digits separated by three spaces
maroon1 is offline  
Old 11-06-2006, 12:55 PM   #4 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

Default

You're on the right track, but you need to add a couple things. First, it would make your life easier to read in user input as a string rather than an integer. So, just use scanner.next() method, which returns a string. At that point, you now have a string representation of the number the user entered. Using a loop, print each character of the string with three spaces concatenated to it.
Code:
System.out.print(character + "   ");

jaeusm is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On