Java_处理英文句子

从控制台接收用户输入的一行英文句子,把句子的最前面两个单词移到句子的最后面去,并整理句子的大小写及标点符号,将新的句子输出。

input: The dog ran through the gate and down the street.   
output: Ran through the gate and down the street, the dog?
input: My coat was too heavy for this warm day!   
output: Was too heavy for this warm day, my coat?

(81条消息) Java split方法详细讲解_一只光头猿的博客-CSDN博客_java split

(81条消息) Java字符串(超超超详细)_白巧克力LIN的博客-CSDN博客_java 字符串

(82条消息) java数组删除数组元素_如何在Java中删除数组元素_cunchi4221的博客-CSDN博客

package t1;
import java.util.Scanner;

public class T1 {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		String x=in.nextLine();

		String[] X=x.split(" ");
		String[] Y= {"0","0"};//用于提取前两个词

		char[] M=X[X.length-1].toCharArray();
		char[] M_new=new char[M.length-1];
		for(int i=0;i<M_new.length;i++) {
			M_new[i]=M[i];
		}
		X[X.length-1]=new String(M_new);//把最后的标点符号去掉了

		for(int i=0;i<2;i++) {
			Y[i]=X[i];
		}
		M=Y[0].toCharArray();
		M[0]=(char)(M[0]+'a'-'A');
		Y[0]=new String(M);//把前两个单词抠出来,并把第一个词的第一个字母转成小写

		M=Y[1].toCharArray();
		M_new=new char[M.length+1];
		for(int i=0;i<M.length;i++) {
			M_new[i]=M[i];
		}
		M_new[M.length]='?';
		Y[1]=new String(M_new);//在第二个词后加问号

		for(int i=0;i<X.length-2;i++) {
			X[i]=X[i+2];
		}
		M=X[0].toCharArray();
		M[0]=(char)(M[0]+'A'-'a');
		X[0]=new String(M);//将原字符串数组前两位删除

		M=X[X.length-3].toCharArray();
		M_new=new char[M.length+1];
		for(int i=0;i<M.length;i++) {
			M_new[i]=M[i];
		}
		M_new[M.length]=',';
		X[X.length-3]=new String(M_new);//加逗号

		for(int i=0;i<X.length-2;i++) {
			System.out.print(X[i]+" ");
		}
		for(int i=0;i<Y.length;i++) {
			System.out.print(Y[i]+" ");
		}
	}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值