3:53 pm - Wednesday March 24, 5199

String Example Program for getBytes()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
@AUTHOR: candid java
@DESCRIPTION: coding for  convert the string into byte
*/

import java.io.*;
public class GetBytes
{
   public static void main(String args[])
   {
     try
     {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("enter the string");
        String s=br.readLine();
        byte b[]=s.getBytes();// converting the string into byte
        for(int i=0;i<b.length;i++) //print  the byte til the string length
        {
          System.out.println("byte for"+" "+s.charAt(i)+"="+b[i]);
        }
    }
  catch(Exception e)
  {
     System.out.println(e);
  }
 }
}

OUTPUT:
enter the string
Application
byte for A=65
byte for p=112
byte for p=112
byte for l=108
byte for i=105
byte for c=99
byte for a=97
byte for t=116
byte for i=105
byte for o=111
byte for n=110

BACK

Filed in: Z-A All Java Codes

Comments are closed.