重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
import java.util.Scanner;
成都创新互联公司主要从事成都网站设计、成都网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务大峪,十载网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108
public class SplitWords {
public static void main(String[] args) {
System.out.println("Please input some english words, separate with ',' or SPACE ");
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
String[] words = input.replace(',', ' ').replace('.', ' ').split("\\s+");
System.out.println("Total " + words.length + " separate word in " + input);
System.out.println("Words with 4 characters are as follows: ");
int count = 0;
for(String str: words){
if(count == 5){
System.out.println();
count = 0;
}
if(str.length() == 4){
System.out.print(str + "\t");
count++;
}
}
}
}
------------------
Please input some english words, separate with ',' or SPACE
Today is Christmas Day, we people in china don't celebrate it. I like china very much.
Total 16 separate word in Today is Christmas Day, we people in china don't celebrate it. I like china very much.
Words with 4 characters are as follows:
like very much
按照你的要求编写的分段函数的Java程序如下
import java.util.Scanner;
public class Segment {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
double x=sc.nextDouble();
double y;
if(x-5){
y=3*x*x+2*x-1;
}else if(x=-5 x=5){
y=x*Math.sin(x)+Math.pow(2,x);
}else{
y=Math.sqrt(x-5)+Math.log10(x);
}
System.out.println("y="+y);
}
}
运行结果
输入 6
输出 y=1.7781512503836436
参考代码如下
import java.util.ArrayList;
public class EnDemo {
public static void main(String[] args) {
ArrayListString preps = new ArrayListString();//用于保存不需要的介词of and等
preps.add("in");
preps.add("and");
preps.add("of");
String str = "Lucy and Lily in the class The day of week is Monday";//一句英语
String[] ss = str.trim().split("\\s+");//按照1个 或者多个空格切分
ArrayListString result = new ArrayListString();//用于保存踢掉分词后的结果
for (int i = 0; i ss.length; i++) {
String temp = ss[i];
if(preps.contains(temp)){//如果是介词.那么继续下次循环
continue;
}else{
result.add(temp);//不是介词 就添加进来
}
}
for (String w : result) {
System.out.print(w+" ");
}
}
}
运行结果:
代码如下:
import java.util.Scanner;
public class App65 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("请输入x值:");
int x = scanner.nextInt();
int y = 0;
if (x 0) {
y = x * x;
} else if (x = 0 x 10) {
y = 2 * x - 1;
} else if (x = 10) {
y = 3 * x - 11;
}
System.out.println("y=" + y);
}
}