Java program to accept a string and print each character of the string along with its ASCII code.



class CalculateAscii {
 public static void main(String args[]) {
  word("Umesh Kushwaha");
 }
 static void word(String s) {
  int len = s.length();
  int a;
  char a1;
  for (int i = 0; i < len; i++) {
   a1 = s.charAt(i);
   a = a1;
   System.out.println(a1 + "–>" + a);
  }
 }
}


Output:

U–>85
m–>109
e–>101
s–>115
h–>104
 –>32
K–>75
u–>117
s–>115
h–>104
w–>119
a–>97
h–>104
a–>97


No comments:

Post a Comment