Files
stringcheck/StringCheck_suzuki.java

69 lines
1.8 KiB
Java
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import java.util.Scanner;
public class StringCheck {
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
// 表示文字列を設定する
String[] display;
display = new String[4];
display[0] = "いまなにしてる?";
display[1] = "何も入力されていません";
display[2] = "投稿文が長すぎます";
display[3] = "↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓";
/*==========文字列読み取り==========*/
// いまなにしてる?
System.out.println(display[0]);
// 標準入力から1行分の文字列を読み取りstrに格納する
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
sc.close();
// 空行を表示する
System.out.println();
// ↓↓↓↓↓↓ 投稿されました ↓↓↓↓↓↓
System.out.println(display[3]);
// 文字列の前後の空白を除去して出力する
str = str.strip();
System.out.println(str); // テスト
/*==========文字数判定==========*/
// strの文字数を取得する
int length = str.length();
/*
// 文字列中の空白を削除して文字列を取得する
String str_wospace = str.replaceAll("\t|\s| ",""); // タブ+半角スペース+改行+改ページ+垂直タブ+全角スペース
System.out.println(str_wospace);
int length = str_wospace.length();
*/
System.out.println(length); // テスト
// 文字数が0かどうかを判定する
boolean wh0 = length == 0;
System.out.println(wh0); // テスト
// 文字数が140を超えているかどうかを判定する
boolean wh140over = length > 140;
System.out.println(wh140over); // テスト
// 残り入力可能文字数を表示する
System.out.println(140-length);
}
}