开发者

Help converting input string into Unicode integers in Java

开发者 https://www.devze.com 2022-12-10 00:03 出处:网络
I\'ve been set an assignment which requires me to capture the input of 5 strings, convert them to uppercase, output them as a string, convert them to their Unicode integers (using the getNumericValue

I've been set an assignment which requires me to capture the input of 5 strings, convert them to uppercase, output them as a string, convert them to their Unicode integers (using the getNumericValue method) and then manipulate the integers using some basic operators.

I get the first part but I am having trouble with the 开发者_如何学Gofollowing:

  1. Using the getNumericValue to convert my single character literal strings into their Unicode integer counterparts.

  2. Being able to assign these ints to variables so I can further process s them with operators, all the examples I have seen have been simple printing out the number and not assigning it to a variable, since I am a Java noob the syntax is still a little confusing for me.

My code is here

If there is a cleaner way of doing what I want please suggest so but without the use of arrays or loops.


I don't understand why you don't want to do this without arrays or loops.

You can get the unicode values (as ints) making up the string via String.codePointAt(), or get the characters via charAt() followed by a getNumericValue() for each character. But regardless, you're going to have to iterate over the set of characters in the string via a loop, or perhaps recursion.


Yes, sounds like op needs to continue researching avenues of learning.

// difficult to code without interfering with 
// instructor's prerogative

char ( array ) = String.getchars();

// Now what, unroll the loop?

...

As noted by Brian, loops are fundamental. I cannot imagine getChars being assigned before simple array techniques.

0

精彩评论

暂无评论...
验证码 换一张
取 消