+ 5
I want to remove the Numbers From words but what is the problem in my Programming have a look and try to find out the error.
2 Antworten
+ 13
error1) String array as a parameter in main method is missing ,
don't know what logic u used , btw here is the logic i thought ... run a loop for each character of String entered & inside that loop ... run another loop for each character of String "1234567890" , inside that inisde loop ... write if statement for comparing character of entered string with string "1234567890"
+ 9
The error you're getting right now regards main(). The parentheses must contain "String[] args" to be a valid main().
There's other issues in your code that arise with converting chars to ints. You can keep everything as chars.
Your second for is meant to search for numbers at each character. If it is one, assign it to keep2 (keep nums). Otherwise, add it to keep (keep letters).The reason why this doesn't work is that the for only checks one number at a time.
I used a Boolean to determine whether a number was found or not. If one wasn't, the char (S) is added to the keepLet string. By the way, the type conversions were unnecessary. chars can be added to strings.
So here's the new fors:
for(int i=0;i<s.length();i++)
{
S = s.charAt(i);
boolean foundNum = false;
for(int j=0;j<n.length();j++)
{
if(S==n.charAt(j))
{
keepNum += S;
foundNum = true;
}
}
if (!foundNum) //Or, if foundNum == false
keepLet += S;
}