*用java做!输入一行字符(英语句子),包含若干单词,相邻的两个单词用空格隔开,编程统计单词的个数。

Java:输入一行字符,统计其中单词的个数。各单词之间用空格分隔,空格数可以是多个~

import java.util.Scanner;
public class Test40031{
public static void main(String []args ){
int ri, repeat,count, word,i;
String line;
char c;
Scanner in=new Scanner(System.in);
repeat=in.nextInt();
in.nextLine();
for(ri=1; ri<=repeat; ri++){
line=in.nextLine();
/*---------*/
count=line.split("\\s+").length;
System.out.println( count);
}
}
}

#include
void main()
{
printf("Please input each word in lowercase letters.
");
gets(string);
for (i=0;(c=string[i])!='\0';i++)
{
if(c==' ') word=0;
else if(word==0)
printf("There are %d words in the line.
",num);
}

字符串
在存储上类似字符数组,它每一位单个元素都是能提取的,字符串的零位是它的长度,如s[0]=10,这提供给我们很多方便,例如高精度运算时每一位都能转化为数字存入数组。
通常以串的整体作为操作对象,如:在串中查找某个子串、求取一个子串、在串的某个位置上插入一个子串以及删除一个子串等。两个字符串相等的充要条件是:长度相等,并且各个对应位置上的字符都相等。
以上内容参考:百度百科-字符串

打完代码才发现没有奖励! 哎 算了吧! 反正打完了。还有别向JAVA这方面发展了,现在不值钱了。过去5年太多人学了。

import java.util.Scanner;
public class LogInSys {
public static void main(String[] args) {
// TODO Auto-generated method stub
int LogOut = 1;
Scanner input = new Scanner(System.in);
System.out.println("欢迎使用XX登录系统");
do{
System.out.print("请输入用户名:");
String userName = input.next();
System.out.print("请输入用户密码:");
String passWord = input.next();
if(userName.equals("admin") && passWord.equals("123456")){
System.out.println("登录成功!");
break;
}else{
System.out.println("登录失败!输入任意整数继续登录!输入0退出系统:");
LogOut = input.nextInt();
}
}while(LogOut != 0);
}
}

JAVA程序 输入一行字符
答:public static void main(String[] args) { System.out.println("你输入的单词数为:"+args.length);StringBuffer strbuffer = new StringBuffer();for(int i=0;i<args.length;i++){ String str = args[i];strbuffer.append(str+" ");System.out.println("正向");System.out.println(str...

java中如何输入一个字符
答:import java.util.*;public class Test_01 { public static void main(String[] args)throws Exception { System.out.println("请输入一个字符");char c=(char)System.in.read();System.out.println(c);} }

在java中怎样在终端输入一个字符串、字符、数字。
答:import java.util.Scanner;public class Test { public static void main(String[] args) { Scanner input=new Scanner(System.in);System.out.println("请输入一个整数:");int length=input.nextInt();//输入一个整数 System.out.println("请输入一个字符或者字符串:");String str=input.nex...

用java编写从标准输入读入一行字符串,打印出其中所有的数字
答:package test1;import java.util.Scanner;/ InputFigures类,功能为在标准输入读入一个字符串,把其中连续的数字打印出来,使用循环实现。 请输入一串数字: 2331 23 1 23123 12 请问你要打印第几个数字? 5 第5个数字是12 3 第3个数字是1 100 对不起,没有这个数字。 0 对不起,没有这个数字。 ...

java编写一个程序,从键盘输入一串字符,从屏幕输出并将其存入a.txt文件...
答:import java.util.Scanner;public class Write{ public static void main(String[] args) { Scanner sc = new Scanner(System.in);System.out.println("请输入要输入的字符");String str=sc.next();System.out.println("你输入的字符为");System.out.println(str);try { BufferedWriter buff = ...

java中,假如我要输入一个字符串,应该怎么写代码啊?
答:import java.util.*;public class zifu { public static void main(String[] args) { int n=100;Scanner scanner = new Scanner(System.in);System.out.print("请输入字符串: ");String yy = scanner.nextLine();StringTokenizer fenxi1 = new StringTokenizer(yy," ");String str[] = new ...

怎么用java实现用从键盘输入一行字符串当遇到句号的时候结束输入?
答:java 使用scanner接收用户从键盘输入的字符,使用while类来判断是否输入的字符为句号,如下代码:import java.util.Scanner;public class ceshi {public static void main(String[] args) {Scanner in = new Scanner(System.in);//新建一个scanner类String[] input = new String[26];int i = 0;do...

Java编写一个应用程序,用户从键盘输入一行含有数字字符的字符串,程序...
答://java.util.Scanner的使用 public class h { public static void main(String args[]){ Scanner input = new Scanner(System.in);System.out.println("请输入字符:");while (input.hasNext()) { String a = input.next();//把字符串中的非数字全部替换为"" 打印 System.out.println(a....

java中如何输入一个字符?
答:你可以先读入一个字符串,然后取一个字符。如果要多次读入一个字符,可以用一个循环依次读取。例如:package konw.test1;import java.util.Scanner;public class InputTest{ public static void main(String[] args) { Scanner input = new Scanner(System.in); char c; String s = ...

java中怎么输入一串字符,要包含的头文件等都麻烦写下?
答:java接收用户输入的字符,可以使用BufferedReader 类,如下代码:package com.qiu.lin.he;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class Ceshi {public static void main(String[] args) {BufferedReader br = new BufferedReader(new Input...

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

联系反馈
Copyright© IT评价网