So my problem is that i'm trying to read a MyString that returns a new Mystring in which every digit -0123456789- has been replaced with a certain char.
Ex:
Blink182 ====>Blinkxxx
import java.io.*;
import java.util.Scanner;
////////////////////////////////////////////////////////////////////////////////
class Hw08
{
//------------------------------------------------------------------------------
public static void main (String [] args) throws Exception
{
Scanner kb = new Scanner(System.in);
MyString s = MyString.read(System.out,kb);
MyString s2 = s.replaceDigits('x');
System.out.println("You entered the MyString \"" + s + "\".");
System.out.println("Results of replaceDigits: " + s2);
}
//------------------------------------------------------------------------------
} // end class Prog1406
////////////////////////////////////////////////////////////////////////////////
class MyString
{
private char [] a;
//------------------------------------------------------------------------------
public MyString ( String s )
{
this.a = new char[s.length()];
for ( int i = 0 ; i < s.length() ; i++ )
{
this.a[i] = s.charAt(i);
}
}
//------------------------------------------------------------------------------
public MyString replaceDigits(char c)
{
char[] result = new char[a.length];
for(int i = 0; i <a.length; i++)
if (a[i]==c) result[i] = c;
else result[i]= a[i];
return new MyString(result);
}
//------------------------------------------------------------------------------
public MyString ( char[] a ) { this.a = a; }
//------------------------------------------------------------------------------
//
// MyString ( char[] a, int used )
//
// Constructs a MyString from an unfilled array of char
//
public MyString ( char[] a, int used )
{
this.a = new char[used];
for ( int i = 0 ; i < used ; i++ ) this.a[i] = a[i];
}
//------------------------------------------------------------------------------
public int length () { return a.length; }
//------------------------------------------------------------------------------
public static MyString read ( PrintStream ps, Scanner sc )
{
if ( ps != null ) ps.print("Enter a String: ");
String s = sc.nextLine();
return new MyString(s);
}
//------------------------------------------------------------------------------
public String toString ()
{
String result = "";
for ( int i = 0 ; i < a.length ; i++ )
{
result += a[i];
}
return result;
}
//------------------------------------------------------------------------------
public static boolean isDigits(char c)
{
return c =='0'||c =='1' || c =='2'|| c =='3'|| c =='4'|| c =='5'||
c =='6'|| c =='7' ||c == '8'|| c =='9';
}
//------------------------------------------------------------------------------
} // end class MyString
////////////////////////////////////////////////////////////////////////////////