整行读入,空格分割;数字与字符串混合读入;String转int

题目内容: dyt喜欢对lrh说的话说反话,现给出lrh说的k句话,输出dyt所说的反话。

输入格式

第一行是样例个数k(k<10) 接下来k行,每行包含lrh说的一句话(每句话长度不超过50,且每句话由英文字母和空格组成(区分大小写),单词间用一个空格隔开,行末无多余空格)。

输出格式

针对每一句话,输出dyt所说的反话,每句话占一行。

输入样例

2
hello world here i come
zxxz Tql

输出样例

come i here world hello
Tql zxxz
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s;
//		int n=sc.nextInt();
//		sc.nextLine();
		s=sc.nextLine();
		int n=Integer.parseInt(s);
		while(n>0) {
			n--;
			s=sc.nextLine();
			String str[]=s.split(" ");
			for(int i=str.length-1;i>=0;i--) {
				System.out.print(str[i]);
				if(i==0) System.out.println();
				else System.out.print(" ");
			}
		}
		sc.close();
	}
}

 split用法:https://www.cnblogs.com/wzj4858/p/8204967.html

 int与String相互转化:https://blog.csdn.net/LJJZJ/article/details/89459402

发布了416 篇原创文章 · 获赞 47 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_42936517/article/details/104026207
今日推荐