Skip to content
Advertisement

Tag: char

Generating Random Number of Characters

I have to create a program that reads in the number of character to be printed, and it will print random chars (a-z, A-Z, 0-9 and characters like !, &, $, etc). And the first character to be printed cannot be a number (0-9). So an example output would be like: Length of Variable? 20 a5fTnO$akP_a12BahsiO This is what I

How do I use the character’s equals() method in Java?

As the String is an object, you need to use the string.equals(string) method to confirm that the two strings are equal. However, why do you use the == to check if two chars are equal, char1 == char2, rather than char1.equals(char2)? Answer Perhaps, this will help to understand the difference on == vs equals.

Replace Unicode escapes with the corresponding character

I’m trying to convert code points, such as u00FC, to the character it represents. An example to explain what I mean: First Console line: Input: Hallu00F6 Second Console line: And Now: Hallö EDIT: Because sometimes it didn’t work with multiple Unicodes in The Trombone Willy’s answer, here is the Code fixed: Answer Joao’s answer is probably the simplest, but this

Count words, java

I want to count words. I use the methods hasNextChar and getChar. The sentence may contain all kind of chars. Here’s my code: It works so far but e.g. when I have a ” . ” at the end it gives me 8 instead of 7 words. Here are some examples of sentences: *„Schreiben Sie ein Praktikanten-Vermittlungs-Programm“ – words: 6

Advertisement