- 最後登錄
- 2024-5-24
- 在線時間
- 29002 小時
- 註冊時間
- 2011-12-11
- 閱讀權限
- 95
- 精華
- 3
- UID
- 10643381
- 帖子
- 3224
- 積分
- 24366 點
- 潛水值
- 77420 米
| 回覆中加入附件並不會使你增加積分,請使用主題方式發佈附件。 本帖最後由 snowflying 於 2014-1-7 11:33 AM 編輯
不知道有沒有誤解意思
- import java.util.Scanner;
- public class Lab {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String str;
- char chk;
- int x = -1;
- int y = -1;
- boolean a = true, b = false;
- System.out.println("Please input a string");
- str = input.next();
- for (int i = 0; i < str.length(); i++) {
- chk = str.charAt(i);
- if (chk == 'r')
- {
- x = i;
- break;
- }
- if (chk == 'n')
- {
- y = i;
- break;
- }
- }
- if ((y > x) && (y != 0))
- System.out.println("N " + y);
- else if ((y < x) && (x != 0))
- System.out.println("R " + x);
- else
- System.out.println("not");
- }
- }
複製代碼 ... |
|