Log In · Register

 
Java/ApComputerSci., User input programs
SkaironFrenzy
post Sep 15 2005, 07:34 PM
Post #1


HOY!!!!!
****

Group: Member
Posts: 268
Joined: Oct 2004
Member No: 55,098



{OK i'm pretty much new to Java and the computer language thing, but I do understand the fundamentals.}

Due:Wednesday, 21,2005

Problem:

Write an application program that inputs one number consisting of four digits from the user; separates the number into its individual digits and prints the separated digits from one another. For example, if the user types in the number 4239, the program should print 4 2 3 9.(hint:Use Mod(%) and Division(/).

Ok this is what I got so far:

import javax.swing.JOptionPane;

public class Separate
{
public static void main(String[] args)
{
String number;
int numberOne;
double mod;
double division;

number=JOptionPane.showInputDialog("Enter 4 numbers");
numberOne= Integer.parseInt(number);


System.exit(0);
}
}


(I tried putting a code box but it screwed up the code.)
Its just the foundation. I cant figure out the rest to separate the numbers. Thanks you all for your help.
 
 
Start new topic
Replies
SkaironFrenzy
post Sep 16 2005, 05:13 AM
Post #2


HOY!!!!!
****

Group: Member
Posts: 268
Joined: Oct 2004
Member No: 55,098



lol. thanks -ALOT. i pretty much get it now.

EDIT
u know that 4239/1000 is not ".4239" its "4.239.

EDIT(again)
OK some can close this now. I figured it out! yay! But it was mostly from your help. Thanks though. This is what I got.

CODE
import javax.swing.JOptionPane;

public class Split
{
    public static void main(String[] args)
    {
 String number;
 double numberOne;

 int thousands;
 double numberTwo;
 double numberThree;  
   
 int hundreds;
 double numberFour;
 double numberFive;
 
 int tens;
 double numberSix;
 double numberSeven;
 
 int ones;
 double numberEight;
 double numberNine;
 
 number=JOptionPane.showInputDialog("Enter a four digit number");
 numberOne= Integer.parseInt(number);
 numberTwo=numberOne%10000.0;
 numberThree=numberTwo/1000.0;  
 thousands=(int)numberThree;
 
 numberFour=numberOne%1000.0;
 numberFive=numberFour/100.0;
 hundreds=(int)numberFive;
 
 
 numberSix=numberOne%100.0;
 numberSeven=numberSix/10.0;
 tens=(int)numberSeven;    
 
 numberEight=numberOne%10.0;
 numberNine=numberEight/1.0;
 ones=(int)numberNine;
 
 System.out.println("Here you go!\n"+thousands+" "+hundreds+" "+tens+" "+ones);
 
 System.exit(0);
    }
}  



so yea someone can close this now. yawn.gif
 

Posts in this topic
SkaironFrenzy   Java/ApComputerSci.   Sep 15 2005, 07:34 PM
mipadi   Okay, well, I didn't feel like building an int...   Sep 15 2005, 09:13 PM
SkaironFrenzy   hmm. thats nice. thank you.but there is no other w...   Sep 15 2005, 09:48 PM
mipadi   Okay. Well, here's a rough algorithm you could...   Sep 15 2005, 10:08 PM
SkaironFrenzy   lol. thanks -ALOT. i pretty much get it now. EDIT...   Sep 16 2005, 05:13 AM
mzkandi   ^ Ok. Topic Closed.   Oct 6 2005, 01:31 PM


Closed TopicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members: