java string get i_在Java中,为什么我会" 必须返回结果类型的字符串" 问题? (In Java, why do I get "must return a result type ...

2014-08-04 18:53:56

0

I'm new at programming with languages. Can anyone explain why do I get that "this method must return a result type of String" issue? And what is the simplest code to achive my goal ? Also what is wrong with my coding?

The goal I want to achive in this method is to return a string if it includes "o" in the first index it should return "o" in the output, as an addition if it includes "z" at the second index of the string, method should return it as "z", if it includes them both, I mean the input string begins with "oz..." method should return a string as "oz".

public String startOz(String str)

{

if (str.length() <= 1)

return str;

else

if(str.substring(0, 1).equals("o"))

if (str.substring(1, 2).equals("z"))

return "oz";

else

return "o";

Thank You.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值