To count the one letter in a word

So basically, I have to write a code for a coding class the program where the user inputs a word and outputs the location of one specific letter.

So for example: If the user input "america" it would output "1" "a"

So basically the output I was expecting was

Enter any Word :  America

Letter? :  a


Well instead, the code I ended up writing counts for all the specific letter so basically...

Enter any Word :  america
Letter? :  a


Here's my code:

import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(;
    System.out.print("Enter any Word : ");
    String Loki =;
    System.out.print("Letter? : ");
    char Thor =".").toLowerCase().charAt(0); 
    int count = 0;
    for (char a : Loki.toCharArray()) {
    if (Thor == a) {

And before you ask I was watching Thor Ragnarok and that's why I named the variables the way they I did

Read more here:

Content Attribution

This content was originally published by Linux2 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: