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
-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,185
  • 5
  • 20
  • 29
-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
  • 1
  • 8
-3
votes
2 answers

How to access a specific character in a String ArrayList

I am trying to print out the words in the ArrayList, given they do not start with an "S". So, I need the first index of each item in the String ArrayList My first attempt was the condition in the if statement to be: if(itemsArrayList.charAt(0) ==…
rhondaoj
  • 1
  • 1
-3
votes
1 answer

How to make uppercase with charAt() method in Java?

I am trying to make a program where a input an email from the user. I have to create a username from the email by deleting the part that comes after ‘@’ and I will display that username to the user. I will ignore the numbers and after a '.' and I…
user12662795
-3
votes
1 answer

charAt(0) gives unexpected output

Doing some summer vacation exercises for Java, and I'm trying to verify social security (specific for my country) Something doesn't add up for me with charAt(0) Given social security "300198", it prints "Error 1" at the moment. public void…
Malthe22
  • 15
  • 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…
Mel Torment
  • 49
  • 1
  • 7
-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
  • 1
  • 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
  • 91
  • 1
  • 12
-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…
1 2 3
19
20