0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

JAVA応用④

Posted at

課題

問題:標準入力からファイルのパスを入力し最後を表示するプログラムを作成せよ
使用ツール:eclipse

package ad;

import java.util.Scanner;

public class adr{

	public static void main(String[] args) {
		System.out.println("ファイルパス");
		String str=extracted().next();

		String[] values= str.split("/");
		String lastOne = values[values.length-1];
				System.out.println("「"+lastOne+"」");
			}

	private static Scanner extracted() {
		return new Scanner(System.in);
	}
					
		}

~~~

## aaa/bbb/cccと入力し他場合の結果

ccc


本日の気付き: lengthを使用することで文字だけでなく("/")区切った部分も表示できる。
本日の学び:先日のを含めるとパターンによりvalues[n]、values.lengthと使い分けが可能。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?