Letter yes yes & letter no no in MATLAB

Split a string into two strings, wherein the first string has all alphabetic letters and the second string has all the remaining characters, maintaining the same order as in the original string.

PREREQUISITE:

Basic concepts on STRING related programming in MATLAB:




ASCII TABLE:



MATLAB CODE:

clc
x=input('Enter the sentence:');
Y=double(x);
q=[];
w=[];
for i=1:length(Y)
    if((Y(i)>=65 && Y(i)<=90) || (Y(i)>=97 && Y(i)<=122))
        q=[q Y(i)];
    else
       w=[w Y(i)];
    end
end
p=char(q);
wc=char(w);
disp(p);
disp(wc);

Explanation:





Output:



JAVA CODE:


import java.io.*;
class Tav
{
public static void main(String args[])throws IOException
{
BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the string:");
String a=r.readLine();
int l=a.length();
int c=0;
int d=0;
char m;

for(int i=0;i<l;i++)
{
m=a.charAt(i);
if((m>=65 && m<=90)||(m>=97) &&(m<=122))
{
c=c+1;
}
else
{
d=d+1;
}
}
char q[]=new char[c];
int k=0;
char w[]=new char[d];
int vc=0;
for(int i=0;i<l;i++)
{
m=a.charAt(i);
if((m>=65 && m<=90)||(m>=97) &&(m<=122))
{
q[k]=m;
k=k+1;
}
else
{
w[vc]=m;
vc=vc+1;
}
}
String ds="";
String xs="";
for(int i=0;i<c;i++)
{
ds=ds+q[i];
}
for(int i=0;i<d;i++)
{
xs=xs+w[i];
}
System.out.print("The alphabets are:"+ds);
System.out.println();
System.out.print("The characters which are not alphabets are:"+xs);
}

}

Output:








No comments