Java Character into integer....

I'm starting to learn how to program in java, I have 2 do a simple program that reads a string like "hello123" and it must tell me how many letters are vocals, consonants and numbers, I have the source code but I have a problem on one command

try{
int x=Integer.parseInt(temp.charAt(i));

I want to know how can I change the 1,2,3 on the string into a integer so I can read ir....someone plz help!!!

Comments

  • package com.horstmann.corejava;
    import java.io.*;
    class InputString
    {
    public static void main(String arg[])
    {
    try{
    System.out.println("Enter a String : st. Hello123 ---> ");
    InputStreamReader isr = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(isr);
    String str = br.readLine();
    System.out.println("You have Entered : ");
    System.out.println(str);
    int len;
    len= str.length();
    System.out.println(len);
    int i;
    char ch;
    int chcount=0;
    int incount=0;
    for (i=0;i<len; i++)
    {
    ch = str.charAt(i);
    if (Character.isLetter(ch))
    {
    chcount++;
    }else{
    incount++;
    }
    }
    System.out.println("No.of characters : " + chcount);
    System.out.println("No.of constants : " + incount);
    }catch(IOException ioe)
    {
    System.out.println(ioe);
    }
    }
    }
    Output:
    Enter your String : Hello1234444
    No. of character = 5
    No. of constants = 7

    Pankaj Sharma
    Bhartitelesoft Ltd.
    New Delhi - 110 020.
    Mob. 09871004365.
    pankaj.sharma.cool@gmail.com
    pankajsharma@kiet.edu

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion