在java中输出一句我爱你中国,我爱你故乡。查找"爱"这个字,输出这句话中有多少个"爱"字.

看我爱你中国多少时间~

两个半小时,再加五分钟。

你用酷狗一截就好了呀,
很容易的!

public class Test {
public static void main(String[] args) {
int count=0;
String a="我爱你中国,中国我爱你";

for(int i=0;i<a.length();i++){
if(a.substring(i, i+1).equals("爱")){
count++;
}
}
System.out.println(count);
}
}

int k=0;
String str = "我爱你中国,我爱你故乡爱爱爱爱";
Pattern pattern1 = Pattern.compile(".*?爱.*?",
Pattern.CASE_INSENSITIVE);
Matcher matcher1 = pattern1.matcher(str);
while(matcher1.find()){
k++;
}
System.out.println(k);

public class Test{
public static void main(String[] args){

String str = "我爱你中国,我爱你故乡。";
String newStr[] = new String[str.length()];
for (int i=0; i<str.length(); i++)
{
newStr[i] = str.substring(i, i + 1);
}
int count = 0;
for (int i=0; i<newStr.length; i++)
{
if ("爱".equals(newStr[i]))
{
count ++;
}
}
System.out.println(count);

}

}

这个我也想问。

在java中输出一句我爱你中国,我爱你故乡。查找"爱"这个字,输出这句话...
答:public class Test { public static void main(String[] args) { int count=0;String a="我爱你中国,中国我爱你";for(int i=0;i

用java说一句情话?
答:"你是我代码中的最优解,我愿用我所有的循环和函数,来表达我对你的爱。"

...怎么往qq聊天窗口中每隔一段时间就输出一句我爱你,并且发送给对方...
答:用线程控制,启动下面的线程就可以了,new Thread(new Task()).start() ;public class Task implements Runnable { private TextArea textArea;public Task(TextArea textArea){ this.textArea = textArea;} public void ...

一道java题
答:=-1) System.out.print((char)data+"-->"); } catch (IOException e) { e.printStackTrace(); }输出结果(result): 我-->爱-->你-->中-->国-->!--> ...

java怎么弄输入数字520表示出我爱你
答:out.println("请输入:520");if(!(sc.nextLine().equals("520"))) {System.out.println("输入错误!");}else {System.out.println("我爱你!");break;}}System.out.println("回答正确,程序结束!");}} ...

JAVA中使用while循环说100遍“我喜欢你”?
答:public static void main(String[] args) {int i = 0;while (i < 100){System.out.println("我喜欢你");i++;}}

求大神帮忙,写一个跟女生表白的程序,最好是java语言写的
答:具体是什么效果的,比如显示什么话什么的,有空可以帮你做一个

java 写程序
答:while(true) { System.out.print("请输入送花的数量:");try { r.giveRose(sc.nextInt());} catch (RoseException e) { sc.close();System.exit(0);}finally { System.out.println("我爱你!");} } } } c...

java循环题目
答:我也还是学生,我最喜欢帮别人做作业的哈~import java.util.Scanner;/*.使用do-while循环:输出询问“我爱你,嫁给我吧?”,选择“你喜欢我吗?(y/n):",如果输入为y则打印”我们形影不离“,若输入为n,则继续询问...

用JAVA输入一句5个字的话,然后将它逆序输出?
答://Test.java public class Test{ public static void main(String[] args){ String s = new String("中国我爱你");int len = s.length();String reverse = "";//initialize a reverse string for(int i = len...

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网