Jump to content

splitting a variable's value into two variables?

- - - - -

  • Please log in to reply
1 reply to this topic

#1
Cruel Hand

Cruel Hand

    Learning Programmer

  • Members
  • PipPipPipPip
  • 109 posts
  • Programming Language:Java
  • Learning:Java, Visual Basic .NET
for example, if I have two integers, x and y, and I assign the value of what the user inputs to x.

If the user inputs 1998, can I assign 19 to x and 98 to y?

thanks :)

---------- Post added at 05:04 PM ---------- Previous post was at 04:47 PM ----------

nevermind, I figured out how to do it. For anyone curious to how I did it, check out this code I wrote:

int x = Integer.parseInt(userInput);

		

		int y = x % 100;

		

		x = x / 100;

the user inputs a number, x. Say the number is 1998.

First, I take the string that the user (inputted?) and convert it to an integer.

next, I take the integer and % it by 10 to get the remainder of 98 and store that in one variable, y, and next I divide the variable x by 10 to get 19.

#2
lethalwire

lethalwire

    while(false){ ... }

  • Members
  • PipPipPipPipPipPipPip
  • 748 posts
  • Programming Language:Java, PHP
  • Learning:Java, PHP
Cool Beans :p




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users