Leetcode: Add Binary (Java) How can it perform addition between one char and one int?

class Solution { public String addBinary(String a, String b) { int len1 = a.length() – 1; int len2 = b.length() – 1; int carry = 0; StringBuilder …

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 …

check if char[] contains only one letter and one int

I have no idea how to check if char[] contains only one letter (a or b) on the first position and only one int (0-8) on the second position. for example a2, b2 I have some this, but I do not know, …

Cannot invoke charAt(int) on the array type String[]

I’m doing a function that counts digits in a string: int countOccurences(String str) { // split the string by spaces in a String a[] = str.split(” “); // search for pattern in a int …

Java – Why can’t I use charAt() to see if a char equals another?

I want to see if a character in my string equals a certain other char value but I do not know what the char in the string is so I have used this: if ( fieldNames.charAt(4) == “f” ) But I get the …

Fastest way to iterate over all the chars in a String

In Java, what would the fastest way to iterate over all the chars in a String, this: String str = “a really, really long string”; for (int i = 0, n = str.length(); i < n; i++) { char c = str....