cannot be resolved to a variable in a for loop in a loop

Big Moe Pasha picture Big Moe Pasha · Mar 19, 2015 · Viewed 8k times · Source

i cannot seem to get the bottom "i" to link to a variable in the for loop below where have i gone wrong?? i have tried to edit it change the variable and put the variable above the for loop all i get is error

also i am using eclipse luna

import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class AssignmentProgramming {

public static void main(String[] args) throws IOException {
    // TODO Auto-generated method stub
    Scanner sc = new Scanner(System.in);

    System.out.println("Please enter a string");


    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String data = reader.readLine();


    char ch =(char) System.in.read();

    int letters=0;

    for(int i=0; i<data.length(); i++);
    {
        char c=data.charAt(i);//<-- This i here
        if (c==ch);
        {letters++;
    }



      }
    System.out.println(letters);
    }

    }

Answer

Baby picture Baby · Mar 19, 2015

remove semicolon ; at the end of your for loop

for(int i=0; i<data.length(); i++);
                                  ^

and at ifstatement

if (c==ch);
          ^