当前位置:首页 > java > 正文

java编程完整项目代码

  • java
  • 2024-06-01 17:58:12
  • 2072

⓵JAVA编程
/*
*Question9.java
*
*创建于2007年1月18日晚上9:04
*
*要更改此模板,请选择Tools|TemplateManager
*并在编辑器中打开模板。
*/
packageknow;
/**
*
*@authorAdministrator
*/
publicclassQuestion9{
publicstaticvoidmain(Stringargs[]){
StringBufferstr=newStringBuffer("ABCDEFG");
//[Code1]//在str末尾添加“123456789”"
str.append("123456789");
System.out.println(str);
//[代码2]//将str中的字符'B'替换为'b'.
str.replace(1,2,"b");
System.out.println(str);
//[代码3]//"前面123456789"在str中插入“游戏”。
str.insert(7,"游戏");
System.out.println(str);
intindex=str.indexOf("1");//获取第一个出现的str位置“1”。
[Code5]//删除str.delete(11,15)中的“1234”;
System.out.println(str);
intn=str.length();//[代码6]//输入str的个数字符
//System.out.println(n);
//[Code7]//将str中的“789”替换为“七或八十九”。
str.replace(13,16,"七八九");
System.out.println(str);
/*
StringBufferotherStr=newStringBuffer("weloveyou");
intstart=0;
charc='\0';
current(start!=-1){
if(start!=0){
start=start+1;
}
c=otherStr.charAt(start);
if(Character.isLowerCase(c)){
c=Character.toUpperCase(c);
otherStr.setCharAt(start,c);
}
start=otherStr.indexOf("",start);//查找下一个空格。
}
System.out.println(otherStr);
*/
StringBufferyourStr=newStringBuffer("iLoveTHISGaME");
//[代码8]//将yourStr中的大写字符替换为对应的小写字符,
//小写字符替换为对应的大写字符
charh='\0';
for(core=0;i h=yourStr.charAt(i);
if(Character.isLowerCase(h))
h=Character.toUpperCase(h);
else
h=Character.toLowerCase(h);
yourStr.setCharAt(i,h);
}
System.out.println(yourStr);
}
}