public class StringStuff{
String myString;
/**
*This constructor sets the instance variable equal to my name.
*/
public void StringStuff(){
myString = "Jacob";
}
/**
*This method accepts a String as a parameter and prints to the screen whether or not it contains more characters than your instance variable. Nothing is returned.
*/
public void whichIsLonger(String s){
int x=s.length();
int y=myString.length();
if (x%26gt;y){
System.out.println("The String s contains more letters than myString.");
}
else{
System.out.println("The string s does not contain more letters than myString.");
}
}
/**
*This method prints the second to last character in it to the screen.
*/
public void secondToLast(){
int z=myString.length();
z=z-2;
char c=myString.charAt(z);
System.out.println(c);
}
public static void main(String[]args){
StringStuff e = new StringStuff();
e,whichIsLonger("Ferret");
e.secondToLast();
}
Programming Help?
/**
*This constructor sets the instance variable equal to my name.
*/
public void StringStuff(){
myString = "Jacob";
}
This is not a constructor. This is just an ordinary method that happens to have the same name as the class. Thus, it won't be called when you say new StringStuff().
A constructor must not have a return type. Remove void.
Should be:
public StringStuff(){
myString = "Jacob";
}
Hope this helps.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment