JAVA求加注解

来源:百度知道 编辑:UC知道 时间:2024/06/05 08:31:36
public class Sentence
{
private String words;
private String Text="";

public Sentence (String text)
{
this.words=text;
}

public String reversedText(int a)
{
Text=Text+words.charAt(a);
if (a>=1)
{
return reversedText(a-1);
}
else
return Text;
}

public void reverse()
{
int i=words.length()-1;
reversedText(i);
}

public String getText(){
return Text;
}

public static void main (String []args)
{
Sentence greeting = new Sentence("Hello!");
greeting.reverse();
System.out.println(greeting.getText());
}
}

求每句都加上详细的注解~``拜托了我刚学~``
最好解释写怎么运行的....这两句是什么意思~`下面两位说的我还是不懂能具体点吗

int i=words.length()-1;
Text=Text+words.charAt(a);

public class Sentence //定义一个访问级别为public(公有的)的类Sentence
{
private String words; //定义一个全局变量的访问级别为private(私有的)的字符串(String)变量words
private String Text=""; //定义一个全局变量的访问级别为private(私有的)的字符串(String)变量Text,并赋值为"";

public Sentence (String text) //定义一个访问级别为public(公有的)的Sentence类的无返回值构造方法,并创建构造方法参数为一个String(字符串)类型的变量,text为传入变量的接收者,便于在该方法内部使用
{
this.words=text; //为该类的私有字符串words赋值,赋值为text,这里的this表示该类的实例(对象),this.(点)该类全局变量即可使用
}

public String reversedText(int a) //定义一个访问级别为public(公有的)的返回String(字符串)类型的方法reversedText,并创建该方法的参数为一个int(整型)的变量,a为传入变量的接收者,便于在该方法内部使用
{
Text=Text+words.charAt(a); //给全局变量Text赋值为Text加全局变量words的第a个字符,字符串相加是依次首尾连接起来的,也就是说String a = "ni"; String b = "hao"; a+b则等于"nihao",该处的charAt(int index)方法是一个能够用来检索特定引索下的字符的String实例的方法,返回一个字符,举例:String a = "abcdefg"; a.charAt(3)则返回字符"d",索引是从0开始的
if (a>=1) //if条件判断,()内为判断条件,这句话意思是如果a 大于等于 1的话执行下