0
import java.io.*;
class Hki
{
public void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
System.out.println("enter the code");
String s=br.readLine();
int l=s.length();
int n=0;
String g="",y="";
for(int i=l-1;i>=0;i--)
{
g=g+s.charAt(i);
}
for(int j=0;j<l;j++)
{
int ch =(int)s.charAt(j);
ch=ch-48;
n=n*10+ch;
if((ch>=65&&ch<=90)||ch==32||(ch>=97&&ch<=122))
{
y=y+(char)ch;
}
}
System.out.println("y="+y);
}
}
output isnt comng..
class Hki
{
public void main()throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
System.out.println("enter the code");
String s=br.readLine();
int l=s.length();
int n=0;
String g="",y="";
for(int i=l-1;i>=0;i--)
{
g=g+s.charAt(i);
}
for(int j=0;j<l;j++)
{
int ch =(int)s.charAt(j);
ch=ch-48;
n=n*10+ch;
if((ch>=65&&ch<=90)||ch==32||(ch>=97&&ch<=122))
{
y=y+(char)ch;
}
}
System.out.println("y="+y);
}
}
output isnt comng..
abhishreya
Feb 08, '13
4 answers
2
You didn't put separate conditions for two digit and three digit codes. For two digit ASCII codes, you need to have a condition like this, if((ch>=65 && ch<=90) || (ch>=97 && ch<=99)). If the character doesn't lie in this range then go for three digit ASCII codes that is from 100 to 122.
khanmansoor
Feb 08, '13
2
1
1
@Praneet - You are correct. It should be g.charAt(j) since string g has the new reversed string.
@Abhishreya - Make the corrections and think about the variable n. It should have an initial value.
khanmansoor
Feb 09, '13
Log in to your account to answer this questions.