Questions tagged [charat]

The charAt() method is used to provide a single character by its index within a string.

The charAt() method is used to provide a single character by its index within a string.

292 questions
3
votes
5 answers

For loop can 'see' forthcoming values in current iteration?

I am working my way through CodingBat's Java exercises and I came across the CountXX problem, which counts the amount of times xx appears in a string. Here is how I solved it (I wasn't expecting it to work): int countXX(String str) { int count =…
alanbuchanan
  • 3,993
  • 7
  • 41
  • 64
3
votes
2 answers

Beginner java using charAt and using user input to display characters

import javax.swing.JOptionPane; public class MyJavaProgramTask4Exercise3 { public static void main(String[] args) { String Namestudent, studentID; Namestudent = JOptionPane.showInputDialog("Type in a student name: "); …
paulc01
  • 41
  • 5
3
votes
7 answers

string index out of bounds error in java (charAt)

Quick question. I have this code in a program: input = JOptionPane.showInputDialog("Enter any word below") int i = 0; for (int j = 0; j <= input.length(); j++) { System.out.print(input.charAt(i)); System.out.print(" "); //don't ask…
Kyle
  • 299
  • 1
  • 2
  • 11
3
votes
2 answers

Android. Strange crash in charAt (setSelection)

I have a very strange crash in application. Stacktrace: java.lang.IndexOutOfBoundsException: charAt: -1 < 0 at android.text.SpannableStringBuilder.charAt(SpannableStringBuilder.java:112) at android.text.Selection.setSelection(Selection.java:84) at…
2
votes
1 answer

Java function charAt

Can anyone tell me what this snippet of code does? In my understanding it returns the sum of the indexes in the string, for example, in string is "Hello" it would return 10? AM I wrong here, please let me know… public String decrString(final String…
2
votes
1 answer

i want to print the value of "i" from 0 to 1000

/*how ican make String.fromCharCode(i) i take value from 0 to 1000 so print out letter every time */ JavaScript For Loop