[java] length
Viewer
*** This page was generated with the meta tag "noindex, nofollow". This happened because you selected this option before saving or the system detected it as spam. This means that this page will never get into the search engines and the search bot will not crawl it. There is nothing to worry about, you can still share it with anyone.
- // Import the Scanner class from its ‘package’java.util
- import java.util.Scanner;
- public class lengthOfWord {
- public static void main(String[] args){
- // Setup an object of the Scanner class.
- Scanner in = new Scanner(System.in);
- System.out.print("Please enter the words: ");
- //Use methods of the new Scanner object to get input
- String str = in.nextLine();
- int length=str.length();
- //訂最後一個單字的位置
- int spaceposition=0;
- //從後面開始算空格位置
- for(int i=length-1 ;i>=0;i--){
- if(str.substring(i,i+1).equals(" ")){
- spaceposition=i;
- break;
- }
- }
- String last =str.substring(spaceposition+1,length);
- System.out.println(last);
- }
- }
Editor
You can edit this paste and save as new:
File Description
- length
- Paste Code
- 24 Sep-2020
- 857 Bytes
You can Share it:
Latest Code Pastes