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.

261 questions
-2
votes
1 answer

Using a method to find the letter in the inputted integer

"Write and test the method that returns a letter of the alphabet from a given word, it the position is given. (Hint: use the method that begins with static char getLetter (String txt, int n)." I've been staring at this question for 20 minutes, can't…
-2
votes
2 answers

Shouldn't input.charAt(0) return a String? Why input.charAt(0) >= int works?

I've been doing exercise. Write a Java program that takes the user to provide a single character from the alphabet. Print Vowel of Consonant, depending on the user input. If the user input is not a letter (between a and z or A and Z), or is a string…
rejnol
  • 3
  • 3
-2
votes
2 answers

Implementing substring checking method using only charAt

I am trying to implement a substring method using only charAt method of the String class The problem occurs when I include the last character in the search term 'hat.' otherwise everything works perfectly. Also when searching for example for 'hat' I…
Abu Muhammad
  • 1,115
  • 5
  • 17
  • 28
-2
votes
3 answers

Creating a program that will give the number of A's both lower and upper case in the user entered string (java)

Alright, so here is my dilemma. Unfortunately my Java teacher does not teach how to start the projects in class, nor does he tell us where to find the information to start the program. This is my first programming course, so I'm still trying to…
-2
votes
3 answers

Picking out parentheses out of a String in Java

I am new to Java and trying to finish a program that will read a statement by the user and and scan to see if the amount of LEFT parenthesis match the RIGHT. The person who started the program created a stack but never made any use of it so I left…
Mr. C
  • 43
  • 8
-3
votes
2 answers

Replace a string character by only using charAt()

I'm new to Java and OOP. I'm currently studying for a class test and have the following question: My task is to replace some characters in a given sentence by only using the length() and charAt() methods. I was given the sentence: "This is the…
-3
votes
1 answer

Java: Finding how many times string occurred in a sentence WITHOUT using API

I am supposed to find how many times the word occurred in a given line of a sentence without using API, except .charAt. Any help would be great! thank you Ex of input: dog My dog is very cute dog Every dog passes by another dog, dogs will bark at…
Aero Hun
  • 11
  • 2
-3
votes
1 answer

How to delete the last group in every line JAVA

If i have this group of lines: 812.12 135.14 646.17 1 812.12 135.14 646.18 1 812.12 135.14 646.19 10 812.12 135.14 646.20 10 812.12 135.14 646.21 100 812.12 135.14 646.22 100 I want to delete the last group after the last space how can I do it. I…
Dany
  • 37
  • 2
  • 8
-3
votes
1 answer

Using java, how do count the occurrences of a character in a string, and then format an output with text listing the locations using loops

I understand how to count the occurrences of specific characters in a string. What I am struggling is printing "The specific character is at location x, y, z". If I place the text within the loop that tests for location, the text is printed multiple…
SeanD
  • 1
  • 2
-3
votes
1 answer

StringIndexOutOfBoundsException in java getText()

I will compare the alphabet with the string you entered. I will proceed as follows when the input character string matches the alphabetic character string. I can not figure out why StringIndexOutOfBoundsException occurs. Where is the problem? …
mina_star
  • 1
  • 1
-3
votes
1 answer

ava.lang.StringIndexOutOfBoundsException: String index out of range: 9 at java.lang.String.charAt(String.java:658)

So I have this piece of code. class Hangman { public static void main(String[] args) { char LetterGuess; int x; int num = 0; //Number of letters in a word int y = 0; //(int)(Math.random() * 16 ); …
-3
votes
2 answers

Showing string with charAt in a do-while loop

index = 0; string1 = '1,2,3,4,5,6,8,9,0#'; string2 = '1,2,3#'; do{ document.write(string1.charAt(index)); index++; } while(string1.charAt(index) != '#'); index = 0; document.write('
'); do{ document.write(string2.charAt(index)); …
ICTMitchell
  • 81
  • 1
  • 10
-3
votes
1 answer

Error at System.out.print(word.charAt(count))

I'm trying to get a user input and print the word starting from the last character and adding the previous one to the next line with one less space in the front, looking like it's aligned to the right. but it shows there's an error…
Doraemon
  • 11
  • 1
  • 3
-3
votes
7 answers

Why do we write A.charAt(i) but not A.charAt[i]? And why do we write " - 'A' "?

public static int get(String A) // it is a method { int count = 1; for (int i = 0; i < A.length(); i++) // So A reads line (any word, for example "Car"), so I understand that length will be 3 and that java will check all the…
-4
votes
1 answer

Does String's charAt() method ever return a negative integer value in Java?

String data = //some String; int val = data.charAt(2); Can val ever have a negative value in any scenario?
aquesh
  • 9
  • 1
  • 6
1 2 3
17
18