Write a program to convert each character of the string into ASCII.
Example 1:
Input: str="abxkwet"
Output: 97 98 120 107 119 101 116
Approach:
Java
public class StringIntoASCII {public static void main(String[] args) {// input stringString str = "abxkwet";// convert string to char arraychar[] letters = str.toCharArray();for (char c : letters) {System.out.print((byte) c+" ");}}}
C++
#include <bits/stdc++.h>using namespace std;int main(){//input stringstring str="abxkwet";//iterate till the length of stringfor(int i=0;i<str.size();i++)cout<<(int)str[i]<<" ";return 0;}
No comments:
Post a Comment