Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis+ 4
Java fractions
So I am making a method for adding fractions, but the user input begins as such: String frac1 = ā5/6ā; String frac2 = ā1/7ā; String frac3 = ā-2/9ā; How can I get java to read the String and interpret it as 2 seperate int variables (numerator, denominator)? Iām assuming parsing but Iām totally boggled how to break up the string and especially how to interpret negative values for calculating 2 fractionsā sum
3 Respostas
+ 4
You can use String.split for get numerator and denominator of fraction then use Integer.valueOf (or Integer.parseInt) for detect if either are valid numbers and get their values like integer
+ 3
Ues regex to split the input to nom/denom
+ 2
Thanks guys, so very helpful!