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
-1
votes
3 answers

charAt() returning weird values

I am trying to make program that convert number to words but when I use charAt(0) to get the value of index 0 its returning me strange values import java.util.Scanner; public class numToWord { public static void main(String[] args) { …
-1
votes
2 answers

how do i use charAt() without main method

i have to use with a method (beginntMitA). somehow it doesn't work without main method. does anyone know how do i fix it? public class StringTest{ public static void beginntMitA(String args[]){ String s = "java"; char ch1 =…
tonini
  • 13
  • 1
  • 4
-1
votes
4 answers

How to have the sum for the numbers in a string line?

Here I in this task I need to use the generated string data to loop over all characters on it then sum only the numbers within the string. example: If we have this data string 5f395d07369071a505ef926527de2ac53e8c29e103dc63398315bc276224b81a Then…
-1
votes
3 answers

Reversing a String from user's input

I have written code to prompt user to input a sentence which will be displayed reversed by the system. I have managed it with a bit of help, but I now struggle to comment my codes to explain each piece of it. I somewhat understand what I have done,…
Jon
  • 19
  • 1
  • 5
-1
votes
1 answer

charAt cannot be dereferenced

Attempting the FizzBuzz problem, however I encounter the issue "charAt cannot be dereferenced". Here is my code below for reference. public String fizzString(String str) { if…
BipoN
  • 93
  • 8
-1
votes
4 answers

split(" ") user text string and printing the first letter in each approved word

The user is supposed to enter multiple words (without regards to lower/uppercase) with space inbetween, this text will then be translated into initials without any spaces included. However, I only want the initials of the words that I approve of, if…
Bucc Olam
  • 5
  • 5
-1
votes
3 answers

How to test if the first letter of a passed String is equal to a char in java?

Here is my code: private String studentId; public void setStudentId(String studentId) { if (studentId != null && studentId.trim().length() > 0 && studentId != " ") { if (studentId.charAt(0) = 'a') { …
-1
votes
2 answers

String index value access

This problem is related to String and array in Java. Say I have a String S= abcd. I have an array index[]={2}. My problem is to find out the value from String S at its index position 2 because array index[] hold 2. I have a target array which…
Saswati
  • 192
  • 8
-1
votes
2 answers

How to fix ".class expected" in Java

Main import java.util.Scanner; public class JT1{ public static void main(String args[]){ String CopyArgs[] = new String[args.length]; for(int i = 0; i < args.length; i++) { CopyArgs[i] = args[i]; } for (int i =…
axaro1
  • 29
  • 1
  • 1
  • 3
-1
votes
1 answer

char cannot be dereferenced Java when trying to input Char and using compareTo

So I'm fairly new to java and I've been stuck on this question. Prompt the user for two characters and store them in two char variables. Compare the variables and print “ is less than ” if the first char is less than the second char. …
asdf1234
  • 1
  • 1
-1
votes
1 answer

Declaring the charAt()

String txt="Hello world"; int count; for(int x = 0; x <= txt.length(); x++) { if (txt.charAt(x) == ' ') { count++; } } My app was force closing after declaring the charAt(), is there any problem with this? & how can i fix it?
Ties
  • 9
  • 1
-1
votes
2 answers

String function "CharAt" storing and displaying numeric values in "char"

Ok guys so i'm using this string function "charAT" to store charater variable to store in char r. But we know user can input anything. When user enters a numeric value like 123 or 5 or anything charAt is storing that in char variable r. Exception…
-1
votes
1 answer

Return first letters of words in a string (javascript)

I keep getting an infinite loop and don't understand why my code doesn't work and keeps crashing the browser.