指定された文字列がパングラムであるかどうかを確認するJavaプログラム
この記事では、指定された文字列がパングラムであるかどうかを確認する方法を理解します。文字列は、アルファベットの大文字と小文字を無視してアルファベットのすべての文字が含まれている場合、パングラム文字列です。
以下は同じのデモンストレーションです-
入力がであると仮定します −
Input string: Abcdefghijklmnopqrstuvwxyz
必要な出力は −
Yes, the string is a pangram
アルゴリズム
Step 1 - START Step 2 - Declare a string value namely input_string. Step 3 - Define the values. Step 4 - Convert the input string to a character array. Step 5 - Iterate over the character of the array and check if the array contains all the alphabets using charAt(i) - 'a'. If yes, it’s a Pangram string. Step 6 - Display the result Step 7 - Stop
例1
ここでは、「main」関数の下ですべての操作をバインドします。
public class Pangram {
static int size = 26;
static boolean isLetter(char ch) {
if (!Character.isLetter(ch))
return false;
return true;
}
public static void main(String args[]) {
String input_string = "Abcdefghijklmnopqrstuvwxyz";
System.out.println("The string is defined as: " +input_string);
int string_length = input_string.length();
input_string = input_string.toLowerCase();
boolean[] is_true = new boolean[size];
for (int i = 0; i < string_length; i++) {
if (isLetter(input_string.charAt(i))) {
int letter = input_string.charAt(i) - 'a';
is_true[letter] = true;
}
}
boolean result;
for (int i = 0; i < size; i++) {
if (!is_true[i])
result = false;
}
result = true;
if (result)
System.out.println("\nYes, the string is a pangram");
else
System.out.println("\nNo, the string is not a pangram");
}
} 出力
The string is defined as: Abcdefghijklmnopqrstuvwxyz Yes, the string is a pangram
例2
ここでは、操作をオブジェクト指向プログラミングを示す関数にカプセル化します。
public class Pangram {
static int size = 26;
static boolean isLetter(char ch) {
if (!Character.isLetter(ch))
return false;
return true;
}
static boolean check_alphabets(String input_string, int string_length) {
input_string = input_string.toLowerCase();
boolean[] is_true = new boolean[size];
for (int i = 0; i < string_length; i++) {
if (isLetter(input_string.charAt(i))) {
int letter = input_string.charAt(i) - 'a';
is_true[letter] = true;
}
}
for (int i = 0; i < size; i++) {
if (!is_true[i])
return false;
}
return true;
}
public static void main(String args[]) {
String input_string = "Abcdefghijklmnopqrstuvwxyz";
System.out.println("The string is defined as: " +input_string);
int string_length = input_string.length();
if (check_alphabets(input_string, string_length))
System.out.println("\nYes, the string is a pangram");
else
System.out.println("\nNo, the string is not a pangram");
}
} 出力
The string is defined as: Abcdefghijklmnopqrstuvwxyz Yes, the string is a pangram
-
指定された文字列が母音回文であるかどうかを確認するPythonプログラム
この記事では、以下に示す問題ステートメントの解決策について学習します。 問題の説明 −文字列(母音と子音の両方の文字を含む)が与えられ、すべての子音を削除してから、結果の文字列が回文であるかどうかを確認します。 ここでは、最初に文字列に存在するすべての子音を削除します。各値を1から計算された最小値まで除算することによって計算されて除数を計算するループ 条件が真であると評価されるたびに、カウンターは1ずつ増加します。 文字列内のすべての子音を削除します。ここで、母音の文字列が回文であるかどうか、つまり、指定された文字列とその反転が同一であるかどうかを確認します。それがpalindromep
-
指定された文字列がパングラムであるかどうかを確認するPythonプログラム
この記事では、特定の問題ステートメントを解決するための解決策とアプローチについて学習します。 問題の説明 文字列入力が与えられた場合、その文字列がパングラムであるかどうかを確認するPythonプログラムを生成する必要があります。 パングラムは、英語のアルファベットコレクションのすべての文字を含む文/一連の単語です。 では、問題を解決する方法を見てみましょう 入力文字列に存在する各文字が、手動で宣言するアルファベットセットに属しているかどうかをチェックするループを使用します。 上記のアプローチの実装は、-によって与えられます。 例 import string def ispangram