如何在java中编写这个程序 [英] How to write this program in java

查看:95
本文介绍了如何在java中编写这个程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果输入: -

我的名字是niroop。



输出应该是: -



我的eman很穷。





[附加信息]



如果用户输入我的名字是niroop。在单词之间有很多空格,单词之间只需要一个空格。



每个偶数单词都应该用字符串表示。

最后不应该全力以赴。



[/ additional info]

If Input:-
"My name is niroop."

Output should be:-

"My eman is poorin."


[additional info]

If user gives input "my name is niroop." with lot of spaces in between the words,it should take only one space between words.

every even word should be reveresed in a string.
In the end full stop should not be reveresed.

[/additional info]

推荐答案

我认为程序应该反转句子中偶数位置的所有单词。

然后你必须:

  • 在偶数位置提取单词(查看 String.split [ ^ ]文档)。
  • 反转每个提取的单词(请参阅此Stack Overflow问题:在Java中反转字符串 [ ^ ])。
  • 使用奇数位置的原始单词和反转单词生成输出句子。
I assume the program should reverse all the words at even positions in the sentence.
Then you have to:
  • Extract the words at even positions (have a look at String.split[^] documentation).
  • Reverse every extracted words (see this Stack Overflow question: "Reverse a string in Java"[^]).
  • Use the original words at odd positions and reversed words to produce the output sentence.


不,如果用户给出输入我的名字是niroop,空格很多就需要空格。

我已经编写了代码并且运行正常。



Ur逻辑不正确,你应该在java中尝试更多的程序并以不同的方式思考,这是我的建议无论谁回复。



或写下代码并告诉我。
No,if user gives input"my name is niroop" with lot of spaces it will take spaces.
I have written the code and its running fine.

Ur logics are not correct,u should pratice more programs in java and think in a different way,that's my suggestion whoever is replying.

or write the code and show me.


这篇关于如何在java中编写这个程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆