Mam następującą klasę:
class Sentence {
String text="";
Sentence(Object ...arg){
this.text = ""; for(Object x:arg){ if(x instanceof String){ text = text+x+" "; text = text.toLowerCase(); } if(x instanceof Integer){ text = text+x+" "; text = text.toLowerCase(); } if(x instanceof Sentence){ text = text+x+" "; text = text.toLowerCase(); } }
}
public String toSrting(){
char x;
String y;
x = text.charAt(0);
y = Character.toString(x);for(int i=0 ; i<text.length()-1 ; i++) { x = text.charAt(i); if(x=='.'){ text=text.substring(0,i)+text.substring(i+1,text.length()); } } y = y.toUpperCase()+this.text.substring(1,text.length()); return y+".";
}
}
i main :
public class L1Z3 {
public static void main(String[] args) {
Sentence s1=new Sentence("tylko","KOT"),
s2=new Sentence("a","myszy", 2),
s3=new Sentence(s1,s2,"calkiem","same"),
s4=new Sentence(s3, "na", new Integer(32), "ulicy");System.out.println(s1);
System.out.println(s2);
System.out.println(s3);
System.out.println(s4);
}
}
chce uzyskać taki wynik:
Tylko kot.
A myszy 2.
Tylko kot a myszy 2 calkiem same.
Tylko kot a myszy 2 calkiem same na 32 ulicy.