分段java英文代码,一段java代码
java编程题,输入一段英文文章,单词之间都已经用空格分隔,本人想以每5个单词为一行输出,怎么写?请指教
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分段函数
按照你的要求编写的分段函数的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
用myeclipse将英文按照空格切分 用java做,将英文按照空格切分,并且抽出of,and等词
参考代码如下
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+" ");
}
}
}
求大神指导用Java编程求分段函数(要求用if…else语句实现)
运行结果:
代码如下:
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);
}
}
网页标题:分段java英文代码,一段java代码
网址分享:http://ybzwz.com/article/phhssd.html