English: How to separate the components of a word or a multi-digit number? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 1

English: How to separate the components of a word or a multi-digit number?

En: How can Java be crushed a word or a multi-digit number and use each of its components separately as a separate variable? What kind of class or method should I use to do this? E.g.: input =1234, var1=12, var2=34 ŁŲ§: Ś†ŚÆŁˆŁ†ŚÆŪŒ Ų¬ŲÆŲ§Ų³Ų§Ų²ŪŒ Ų§Ų¬Ų²Ų§ŪŒ ŪŒŚ© Ś©Ł„Ł…Ł‡ ŪŒŲ§ ŪŒŚ© Ų¹ŲÆŲÆ Ś†Ł†ŲÆ Ų±Ł‚Ł…ŪŒ ŲØŲ§ Ų¬Ų§ŁˆŲ§ Ś†Ł‡ Ų·ŁˆŲ± Ł…ŪŒ ŲŖŁˆŲ§Ł† ŲØŲ§ Ų¬Ų§ŁˆŲ§ Ų§Ų¬Ų²Ų§ŪŒ ŪŒŚ© Ś©Ł„Ł…Ł‡ ŪŒŲ§ ŪŒŚ© Ų¹ŲÆŲÆ Ś†Ł†ŲÆ Ų±Ł‚Ł…ŪŒ Ų±Ų§ Ų§Ų² ŪŒŚ©ŲÆŪŒŚÆŲ± Ų¬ŲÆŲ§ Ś©Ų±ŲÆ Łˆ Ų§Ų² Ł‡Ų± Ś©ŲÆŲ§Ł… Ų§Ų² Ų§Ų¬Ų²Ų§ŪŒ Ų¬ŲÆŲ§Ų“ŲÆŁ‡ Ų¢Ł† ŲØŁ‡ Ų¹Ł†ŁˆŲ§Ł† Ł…ŲŖŲŗŪŒŲ±ŪŒ Ų¬ŲÆŲ§ŚÆŲ§Ł†Ł‡ Ų§Ų³ŲŖŁŲ§ŲÆŁ‡ Ś©Ų±ŲÆŲŸ ŲØŲ±Ų§ŪŒ Ų§ŪŒŁ† Ś©Ų§Ų± Ś†Ł‡ Ś©Ł„Ų§Ų³ ŪŒŲ§ Ł…ŲŖŁˆŲÆ Ł‡Ų§ŪŒŪŒ Ł†ŪŒŲ§Ų² Ų§Ų³ŲŖŲŸ Ł…Ų«Ų§Ł„: ŁˆŲ±ŁˆŲÆŪŒ=Ū±Ū²Ū³Ū“ŲŒ Ł…ŲŖŲŗŪŒŲ± Ų§ŁˆŁ„=Ū±Ū²ŲŒ Ł…ŲŖŲŗŪŒŲ± ŲÆŁˆŁ…=Ū³Ū“

14th Jan 2018, 3:10 PM
Amir01
Amir01 - avatar
3 Respostas
+ 2
String has a method substring, which returns a specified part of the string given indices from and to String str="1234" String s1=str.substring(0, 2) String s2=str.substring(2,4) s1 will be "12" s2 will be "34"
14th Jan 2018, 3:25 PM
michal
+ 1
A more complex way is to write your data into an array. Then write your own method for seperating the array. E.g. create 2 Arrays half the size and fill them with array.copy... but in most cases michals answer is usable, easier, prettier, and simply better.
14th Jan 2018, 3:51 PM
Andreas K
Andreas K - avatar
0
thank a lot!
14th Jan 2018, 3:28 PM
Amir01
Amir01 - avatar