一串英语!!!!求里面第二个two首字母大写输出!!!!救救孩子!!!!

qq_40766358 2017-12-06 05:08:52



第五小题!!!!!感激不尽!!!!!

第四个最好能一块说说,如果不能就算了哈哈哈
...全文
568 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
System.out.println("T")
qq_41391935 2017-12-14
  • 打赏
  • 举报
回复
#第4题:String与StringBuffer的性能区别? 答:使用String每次相加都会产生临时字符串,如果拼接10000个临时字符串,会产生将近2万个临时字符串,非常耗内存.而StringBuffer则 没有这个问题,StringBuffer是线程安全的,适合多线程.如果是单线程环境建议使用StringBuilder //#第5题: public static void main(String[] args) { String str="Nature has given us that two ears,two eyes,and but one tongue," + "to the end that we should hear and see more than we speak"; int index=str.lastIndexOf("two"); char ch=str.charAt(index); StringBuilder stringBuilder=new StringBuilder(); stringBuilder=stringBuilder.append(str.substring(0, index)).append(Character.toUpperCase(ch)).append(str.substring(index+1)); System.out.println(stringBuilder); }
笃定i 2017-12-14
  • 打赏
  • 举报
回复
String str = "Nature has given us that two ears, two eyes, and but"; int index = str.lastIndexOf("two"); String t = str.substring(index,index+1); System.out.println(t.toUpperCase());
rickylin86 2017-12-13
  • 打赏
  • 举报
回复

public class Test{
	public static void main(String[] args){
		String str = "Nature has given us that two ears, two eyes, and but one tongue, to the end that we should hear and see more than we speak";
		System.out.println(str);
		System.out.println(str.replaceAll("(^.*)(?<=\\b)two(?=\\b)","$1Two"));
	}
}
张三顺 2017-12-13
  • 打赏
  • 举报
回复
String name="sadasdastwosadasdasdastwoasdasdasdtwopp"; StringBuffer sb = new StringBuffer(name); int s =name.lastIndexOf("two"); sb.replace(s, s+1, name.substring(s, s+1).toUpperCase());
莱克丶番茄 2017-12-13
  • 打赏
  • 举报
回复
indexOf获取最后一个two的位置,将获得的索引位置的字母变大写toUpperCase
天之上有什么 2017-12-07
  • 打赏
  • 举报
回复
七楼第四题全解,五楼第五题提示,去看看String类和StringBuffer的常用方法就知道了
beryl_cap 2017-12-06
  • 打赏
  • 举报
回复
StringBuffer 用时少
beryl_cap 2017-12-06
  • 打赏
  • 举报
回复
第四题 //生成指定长度的随机字符串 public static String createRandomString(int length) { char ch[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1' }; Random random = new Random(); if (length > 0) { int index = 0; char[] temp = new char[length]; int num = random.nextInt(); for (int i = 0; i < length % 5; i++) { temp[index++] = ch[num & 63]; num >>= 6; } for (int i = 0; i < length / 5; i++) { num = random.nextInt(); for (int j = 0; j < 5; j++) { temp[index++] = ch[num & 63]; num >>= 6; } } return new String(temp, 0, length); } else if (length == 0) { return ""; } else { throw new IllegalArgumentException(); } } public static void main(String[] args) { String tenLength = ""; int length = 10000; String strTime = ""; long s = System.currentTimeMillis(); for (int i = 0;i < length;i++){ tenLength = createRandomString(10); strTime += tenLength; } System.out.println("String use : " + (System.currentTimeMillis() - s) +"ms." + strTime); StringBuffer sbTime = new StringBuffer(); s = System.currentTimeMillis(); for (int i = 0;i < length;i++){ tenLength = createRandomString(10); sbTime.append(tenLength); } System.out.println("StringBuffer use : " + (System.currentTimeMillis() - s) +"ms." + sbTime); }
thinking code 2017-12-06
  • 打赏
  • 举报
回复
优化一下
		String str = "Nature has given us that two ears, two eyes, and but one tongue, to the end that we should hear and see more than we speak";
		StringBuffer sb = new StringBuffer(str);
		int index = str.lastIndexOf(" two ");
		char c = str.charAt(index + 1);
		String ss = String.valueOf(c).toUpperCase();
		sb = sb.replace(index + 1, index + 2, ss);
		System.out.println(sb.toString());
在发呆的_fy 2017-12-06
  • 打赏
  • 举报
回复
Java中字符串中子串的查找共有四种方法,如下: 1、int indexOf(String str) :返回第一次出现的指定子字符串在此字符串中的索引。 2、int indexOf(String str, int startIndex):从指定的索引处开始,返回第一次出现的指定子字符串在此字符串中的索引。 3、int lastIndexOf(String str) :返回在此字符串中最右边出现的指定子字符串的索引。 4、int lastIndexOf(String str, int startIndex) :从指定的索引处开始向后搜索,返回在此字符串中最后一次出现的指定子字符串的索引。 很清楚了吧 利用lastindexof
逗比123号 2017-12-06
  • 打赏
  • 举报
回复
学过string类就可以写了
thinking code 2017-12-06
  • 打赏
  • 举报
回复
		String str = "Nature has given us that two ears, two eyes, and but one tongue, to the end that we should hear and see more than we speak";
		int index = str.lastIndexOf(" two ");
		String str1 = str.substring(0, index + 1);
		String str2 = str.substring(index + 1, index + 2);
		String str3 = str.substring(index + 2);
		
		String newStr = str1.concat(str2.toUpperCase()).concat(str3);
		
		System.out.println(newStr);
soton_dolphin 2017-12-06
  • 打赏
  • 举报
回复
System.out.println("Nature has given us that two ears, Two eyes, and but one tongue, to the end that we should hear and see more than we speak.");
Braska 2017-12-06
  • 打赏
  • 举报
回复
就是考stringbuilder的用法啊。。

public static void main(String[] args) {
        String word = "two", target = "Two";
        String str = "Nature has given us that two ears, two eyes, and but...";

        StringBuilder stringBuilder = new StringBuilder(str.length());
        stringBuilder.append(str);

        int index = str.lastIndexOf(word);
        stringBuilder = stringBuilder.replace(index, index + word.length(), target);
        System.out.println(stringBuilder.toString());
    }

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧