こんにちは私はエラーが含まれていませんが、私は特殊文字に問題があります私は適切な文字の代わりに四角形を持っている私はどのようにスペースに対処するのか分からない私のコード暗号化セザールアルゴリズム
package cesar;
import java.util.Scanner;
public class Cesar {
private static short codeMajuscule=65;
private static short codeMinuscule=97;
private static short tailleAlph = 26;
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("Entrer la chaine a crypter");
String phrase = sc.next();
System.out.println("entrer votre cle");
int c= sc.nextInt();
System.out.println("la phrase après transformation " + chiffrement( phrase , c));
}
private static String chiffrement(String ch , int n){
String chDecripte="";
ch=ch.replaceAll("[éèêë]", "e");
ch=ch.replaceAll("[Ç]", "C");
ch=ch.replaceAll("[ÈÉÊË]", "E");
ch=ch.replaceAll("[ÌÍÎÏ]", "I");
ch=ch.replaceAll("Ñ", "N");
ch=ch.replaceAll("ÒÓÔŒ", "O");
ch=ch.replaceAll("ÙÚÛÜ", "U");
ch=ch.replaceAll("ÝŸ", "Y");
ch=ch.replaceAll("àáâæ", "a");
ch=ch.replaceAll("[ÀÁÂÆ]", "A");
ch=ch.replaceAll("[èéêë]", "e");
ch=ch.replaceAll("[ìíîï]", "i");
ch=ch.replaceAll("[ñ]", "n");
ch=ch.replaceAll("[òóôœ]", "o");
ch=ch.replaceAll("[ùúûü]", "u");
ch=ch.replaceAll("[ýÿ]", "y");
for(int i = 0 ; i < ch.length() ; i++){
if(ch.codePointAt(i) >= codeMajuscule &&
ch.codePointAt(i) <= (codeMajuscule + tailleAlph)){
chDecripte += (char) ((ch.codePointAt(i) - codeMajuscule + n) % tailleAlph + codeMajuscule) ;
}else if(ch.codePointAt(i) >= codeMinuscule &&
ch.codePointAt(i) <= (codeMinuscule + tailleAlph)){
chDecripte += (char) ((ch.codePointAt(i) - codeMinuscule + n) % tailleAlph + codeMinuscule) ;
}else{
chDecripte += ch.charAt(i);
}
}
return chDecripte;
}
}
と感謝
問題を示す入出力の例を挙げることができますか? – coolioasjulio
私はélèveなどを書いているときには、私はspecil caracterの場所に空の四角があります。私は、私がスペースを持って何かを書くときにもデコードしたいと思っています。コード –
これはあなたのスペースエラーの原因かもしれませんが、あなたは改行線区切り記号を消費していません。 'sc.next();'を 'sc.nextLine()'に置き換えます。これにより、入力行全体が消費されます。 'next()'は次のスペースまで入力のみを消費します。 – coolioasjulio