62,614
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
String input = "Flanked by climate change campaigner and former US vice-president Al Gore, Mr Palmer announced his party would vote against the Government's bid to abolish the Clean Energy Finance Corporation, the Renewable Energy Target and the Climate Change Authority.";
final int MAX_COUNT = 40;
ArrayList<String> array = new ArrayList<String>();
int beginIndex = 0, endIndex = 0, count = 0;
char LineNumber = 'A';
for(int i=0;i<input.length();i++){
if(input.charAt(i)==' '){
endIndex = i;
}
count++;
if(count>=MAX_COUNT){
if(i+1<input.length() && input.charAt(i+1)==' '){
endIndex = i+1;
}
array.add(LineNumber+" "+input.substring(beginIndex, endIndex));
LineNumber++;
beginIndex=endIndex+1;
count = i-endIndex;
}
}
if(endIndex<input.length()){
array.add(LineNumber+" "+input.substring(beginIndex));
}
for(String value : array){
System.out.println(value);
}
}
class AddBigChar
{
public static void main(String[] args)
{
String str = "Flanked by climate change campaigner and former US vice-president Al Gore, Mr Palmer announced his party would vote against the Government's bid to abolish the Clean Energy Finance Corporation, the Renewable Energy Target and the Climate Change Authority.";
int length = 38;
StringBuilder sb = new StringBuilder();
for(int i=0; i<str.length()/length+1; i++){
if(i==0){
sb.append(((char)(65+i))+" "+new String(str.substring(0,length-1))+"\n");
} else if(i==(str.length()/length)) {
sb.append(((char)(65+i))+" "+new String(str.substring(i*length-1, str.length()-1))+"\n");
} else {
sb.append(((char)(65+i))+" "+new String(str.substring(i*length-1, (i+1)*length-1)+"\n"));
}
}
System.out.println(sb.toString());
}
}