Write a Java application titled MyStringTest that creates an instance of the String class and initializes this instance with a String literal. Use a for loop structure to print the string in reverse order. Implement the following two String member methods to complete the assignment.
- length( )
- charAt( )
Title your program to test the String class MyStringTest.
This is my code thus far, but cannot figure out my errors!
/**
*
* 12/15/2013
* Assignment 9.4
* Write a Java application that creates an instance of the String class and
* initializes this instance with a String literal.
* Bellevue University
*/
class MyStringTest
{
String name;
public MyStringTest(String temp)//constructer that initializes your object
{
name=temp;
}
MyStringTest() {
throw new UnsupportedOperationException("MyStringTest"); //To change body of generated methods, choose Tools | Templates.
}
public void reverse()
{
int len = name.length();
String s="";
for(int i=len-1; i>=0; i--)
{
char c=name.charAt(i);
String s1 = Character.toString(c);
s=s.concat(s1);
}
System.out.println (s);
}
void reverse(String sajha) {
throw new UnsupportedOperationException("tseTgnirtSyM"); //To change body of generated methods, choose Tools | Templates.
}
}
public class test
{
public static void main(String args[])
{
MyStringTest mst = new MyStringTest("tseTgnirtSyM");
mst.reverse();
}
}
class MyStringTest2
{
public void reverse(String name)
{
int len = name.length();
String s="";
for(int i=len-1; i>=0; i--)
{
char c=name.charAt(i);
String s1 = Character.toString(c);
s=s.concat(s1);
}
System.out.println (s);
}
}
public class test2
{
public static void main(String args[])
{
MyStringTest mst = new MyStringTest();
mst.reverse("MyStringTest");
}
}
Can anyone help me, please?