Example usage for java.lang String charAt

List of usage examples for java.lang String charAt

Introduction

In this page you can find the example usage for java.lang String charAt.

Prototype

public char charAt(int index) 

Source Link

Document

Returns the char value at the specified index.

Usage

From source file:MainClass.java

public static void main(String[] arg) {
    String str = "abcde";

    System.out.println(str.charAt(2));
}

From source file:Main.java

public static void main(String[] argv) {
    String string = "animals";
    System.out.println(string.charAt(0)); // a 
    System.out.println(string.charAt(6)); // s 
    System.out.println(string.charAt(7)); // throws exception 
}

From source file:Main.java

public static void main(String[] args) {
    int count = 1;
    String userInput = "this is a test";
    char ch = userInput.charAt(0);
    for (int i = 1; i < userInput.length(); i++) {
        if (userInput.charAt(i) == ch)
            count++;/*from  w ww .j  a  v a2 s .  c o m*/
    }
    System.out.println(count);

}

From source file:CheckVersion.java

public static void main(String[] args) {
    String version = System.getProperty("java.version");
    char minor = version.charAt(2);
    char point = version.charAt(4);
    if (minor < '4' || point < '1')
        throw new RuntimeException("JDK 1.4.1 or higher " + "is required to run the examples in this book.");
    System.out.println("JDK version " + version + " found");
}

From source file:Main.java

public static void main(String args[]) {
    String strOb1 = "java2s.com";

    System.out.println("Char at index 3 in strOb1: " + strOb1.charAt(3));

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String test = "ABCD";
    for (int i = 0; i < test.length(); ++i) {
        char c = test.charAt(i);
        int j = (int) c;
        System.out.println(j);/*from www  .  j  a va  2  s .  co  m*/
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String test = "ABCD";
    for (int i = 0; i < test.length(); ++i) {
        char c = test.charAt(i);
        System.out.println((int) c);
    }/*  ww  w. j ava 2s.co m*/
}

From source file:Main.java

public static void main(String[] args) {
    boolean flag = true;
    String str = "123";

    for (int i = 0; i < str.length(); i++) {
        if (str.charAt(i) > 48 && str.charAt(i) < 58) {
            flag = false;//  www .  j ava  2 s  .c om
            break;
        }
    }
    if (flag == true) {
        System.out.println("String is a valid String..");
    } else {
        System.out.println("String contains number");
    }
}

From source file:Main.java

public static void main(String args[]) throws IOException {
    BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("Enter the char:");
    String str = buff.readLine();
    for (int i = 0; i < str.length(); ++i) {
        char c = str.charAt(i);
        int j = (int) c;
        System.out.println("ASCII OF " + c + " = " + j + ".");
    }// www  . j  a  v  a2  s  . c o m
}

From source file:Main.java

public static void main(String[] args) {
    int y = 0;/*from  w  ww .ja  va2 s  .c om*/
    char letter = 'e';
    String food = "this is a test";

    for (int x = 0; x < food.length(); x++) {
        if (food.charAt(x) == letter) {
            y++;
        }
    }

    System.out.println(y);
}