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 ŁŲ§: ŚŚÆŁŁŚÆŪ Ų¬ŲÆŲ§Ų³Ų§Ų²Ū Ų§Ų¬Ų²Ų§Ū ŪŚ© Ś©ŁŁ Ł ŪŲ§ ŪŚ© Ų¹ŲÆŲÆ ŚŁŲÆ Ų±ŁŁ Ū ŲØŲ§ Ų¬Ų§ŁŲ§ ŚŁ Ų·ŁŲ± Ł Ū ŲŖŁŲ§Ł ŲØŲ§ Ų¬Ų§ŁŲ§ Ų§Ų¬Ų²Ų§Ū ŪŚ© Ś©ŁŁ Ł ŪŲ§ ŪŚ© Ų¹ŲÆŲÆ ŚŁŲÆ Ų±ŁŁ Ū Ų±Ų§ Ų§Ų² ŪŚ©ŲÆŪŚÆŲ± Ų¬ŲÆŲ§ Ś©Ų±ŲÆ Ł Ų§Ų² ŁŲ± Ś©ŲÆŲ§Ł Ų§Ų² Ų§Ų¬Ų²Ų§Ū Ų¬ŲÆŲ§Ų“ŲÆŁ Ų¢Ł ŲØŁ Ų¹ŁŁŲ§Ł Ł ŲŖŲŗŪŲ±Ū Ų¬ŲÆŲ§ŚÆŲ§ŁŁ Ų§Ų³ŲŖŁŲ§ŲÆŁ Ś©Ų±ŲÆŲ ŲØŲ±Ų§Ū Ų§ŪŁ Ś©Ų§Ų± ŚŁ Ś©ŁŲ§Ų³ ŪŲ§ Ł ŲŖŁŲÆ ŁŲ§ŪŪ ŁŪŲ§Ų² Ų§Ų³ŲŖŲ Ł Ų«Ų§Ł: ŁŲ±ŁŲÆŪ=Ū±Ū²Ū³Ū“Ų Ł ŲŖŲŗŪŲ± Ų§ŁŁ=Ū±Ū²Ų Ł ŲŖŲŗŪŲ± ŲÆŁŁ =Ū³Ū“
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"
+ 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.
0
thank a lot!