자바의 회문
문자열이나 숫자를 뒤집어도 그대로 유지되는 경우를 회문이라고 합니다. 예를 들어 'MADAM'은 뒤집어도 'MADAM'으로 표기되므로 회문 문자열입니다. 하지만 'LUCKY'의 경우 이 문자열을 역으로 바꾸면 'YKCUL'이 되므로 회문이 아닙니다. 회문 번호 중 일부는 365563, 48984, 12321, 171, 88, 90009, 343이고 회문 문자열 중 일부는 MADAM, MALAYALAM, LOL, DAD, MOM, C++&++C 등입니다. 다음 섹션에서 회문의 논리와 구현을 살펴보겠습니다. 이번 주제에서는 Java의 Palindrome에 대해 알아보겠습니다.
무료 소프트웨어 개발 과정 시작
웹 개발, 프로그래밍 언어, 소프트웨어 테스팅 등
Java Palindrome의 논리
숫자가 회문인지 확인하려면 다음 알고리즘을 사용할 수 있습니다.
- 회문인지 아닌지 확인해야 할 문자열이나 숫자를 입력받아보세요.
예를 들어 숫자 353을 입력한다고 가정해 보겠습니다.
- 입력 숫자를 가져와 임시 변수에 복사합니다
353-> temp
- for, while 또는 원하는 방법을 사용하여 반전하세요.
Reversednumber: rev=353
- 입력된 숫자와 반전된 숫자를 비교해보세요.
같으면 그 숫자를 회문수라고 합니다.
그렇지 않으면 회문번호가 아닙니다.
즉,
If(inputnum==rev) { then palindrome } Else not palindrome
다양한 방법으로 Palindrome을 테스트하는 방법은 무엇입니까?
주어진 입력 숫자가 회문인지 여부를 확인하는 방법에는 여러 가지가 있습니다.
- For 루프
- While 루프
- 라이브러리 방법(문자열용)
각각 자세히 살펴보겠습니다.
1. for 루프를 사용하여 회문 번호를 확인하는 프로그램
코드:
//Java program to check whether a String is a Palindrome or not using For Loop import java.util.*; public class PalindromeNumberExample { //main method public static void main(String[] args) { int r=0 ; //reversed Integer int rem, num; //remainder and original number Scanner s = new Scanner(System.in); System.out.print("Enter number that has to be checked:"); num = s.nextInt(); //Store the number in a temporary variable int temp = num; //loop to find the reverse of a number for( ;num != 0; num /= 10 ) { rem = num % 10; // find the modulus of the number when divided by 10 r = r * 10 + rem; } //check whether the original and reversed numbers are equal if (temp == r) { System.out.println(temp + " is input number"); System.out.println(r + " is the reversed number"); System.out.println("Since they are equal " + temp + " is a palindrome number"); } else { System.out.println(temp + " is input number"); System.out.println(r + " is the reversed number"); System.out.println("Since they are not equal " + temp + " is not a palindrome number"); } } }
출력 1:
여기서 353은 거꾸로 해도 똑같으므로 회문으로 간주합니다.
출력 2:
여기서 234는 뒤집어도 그대로 남아 있으므로 회문으로 간주되지 않습니다.
2. While 루프를 이용하여 회문수를 확인하는 프로그램
코드:
//Java program to check whether a number is a Palindrome or not using While Loop import java.util.*; public class PalindromeNumberExample { public static void main(String[] args) { int r=0, rem, num; Scanner s = new Scanner(System.in); System.out.print("Enter number that has to be checked:"); num = s.nextInt(); //Store the number in a temporary variable int temp = num; //loop to find the reverse of a number while( num != 0 ) { rem= num % 10; r= r * 10 + rem; num=num/10; } //check whether the original and reversed numbers are equal if (temp == r) { System.out.println(temp + " is input number"); System.out.println(r + " is the reversed number"); System.out.println("Since they are equal " + temp + " is a palindrome number"); } else { System.out.println(temp + " is input number"); System.out.println(r + " is the reversed number"); System.out.println("Since they are not equal " + temp + " is not a palindrome number"); } } }
출력 1:
출력 2:
3. 라이브러리 메소드를 사용하여 회문 번호를 확인하는 프로그램(문자열의 경우)
코드:
//Java program to check whether a String is a Palindrome or not using Library method import java.util.*; public class PalindromeNumberExample { //Function to check whether the string is palindrome or not public static void PalindromeCheck(String str) { // reverse the input String String rev = new StringBuffer(str).reverse().toString(); // checks whether the string is palindrome or not if (str.equals(rev)) { System.out.println("input string is :" + str); System.out.println("Reversed string is :" + rev); System.out.println("Since the input and reversed string are equal, "+ str +" is a palindrome"); } else { System.out.println("input string is :" + str); System.out.println("Reversed string is :" + rev); System.out.println("Since the input and reversed string are not equal, "+ str +" is not a palindrome"); } } public static void main (String[] args) { PalindromeCheck("MALAYALAM"); } }
출력:
여기서 입력 문자열은 프로그램 자체에 전달됩니다.
문자열이 회문인지 확인하려면 다음 프로그램도 사용됩니다.
코드:
//Java program to check whether a String is a Palindrome or not import java.util.*; public class PalindromeNumberExample { public static void main(String args[]) { String st, rev = ""; Scanner sc = new Scanner(System.in); System.out.println("Enter the string that has to be checked:"); st = sc.nextLine(); int len = st.length(); //length of the string for ( int i = len- 1; i >= 0; i-- ) rev = rev + st.charAt(i); if (st.equals(rev)) { System.out.println("input string is :" + st); System.out.println("Reversed string is :" + rev); System.out.println("Since the input and reversed string are equal, "+ st +" is a palindrome"); } else { System.out.println("input string is :" + st); System.out.println("Reversed string is :" + rev); System.out.println("Since the input and reversed string are not equal, "+ st +" is not a palindrome"); } } }
출력:
결론
뒤집어도 그대로 유지되는 숫자를 회문이라고 합니다. 회문은 문자열로도 확인할 수 있습니다. 회문 숫자와 문자열 중 일부는 MOM, MALAYALAM, DAD, LOL, 232, 1331 등입니다. 이 문서에서는 알고리즘, 메서드, 구현 등과 같은 회문의 여러 측면을 다룹니다.
위 내용은 자바의 회문의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undress AI Tool
무료로 이미지를 벗다

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

Adeadlockinjavaoccurswhentwoormorethreadsareblockedsforever,, 일반적으로, 일반적으로 duetocircularwaitcausedbyinconsentlockordering; thiscanbeptrededbectedbectedbectedbectedbectedbectefeartefournecessaryconditions —MutualExclusion, holdandwait, nopualwait, nopualclusion, nopualclusion

useOptional.empty (), 옵션.의 (), andoptional.ofnullable () theCreateOptionalInstancesDependingOnsabsent, non-null, orpossiblynull.2.checkforvaluessafelyusingispresent () orpreferlyinglioid () toaviDIDHECK.3

SpringDataJPA 및 최대 절전 모드의 핵심은 다음과 같습니다. 1. JPA는 사양이고 최대 절전 모드는 구현, SpringDataJPA 캡슐화는 DAO 개발을 단순화합니다. 2. 엔티티 클래스 @entity, @id, @column 등을 통해 데이터베이스 구조를 맵핑합니다. 3. 저장소 인터페이스는 JParePository를 상속하여 CRUD 및 명명 된 쿼리 메소드를 자동으로 구현합니다. 4. 복잡한 쿼리 @Query 주석을 사용하여 JPQL 또는 기본 SQL을 지원합니다. 5. SpringBoot에서는 스타터 종속성을 추가하고 데이터 소스 및 JPA 속성을 구성하여 통합이 완료됩니다. 6. 거래는 @transactiona에 의해 이루어집니다

제공자 메커니즘을 통해 알고리즘을 구현하는 MessageDigest, Cipher, Keygenerator, Securandom, Signature, Keystore 등과 같은 JCA 핵심 구성 요소를 이해합니다. 2. SHA-256/SHA-512, AES (256 비트 키, GCM 모드), RSA (2048 비트 이상) 및 Securerandom과 같은 강력한 알고리즘 및 매개 변수를 사용하십시오. 3. 하드 코딩 된 키를 피하고 KeyStore를 사용하여 키를 관리하고 PBKDF2와 같은 안전하게 파생 된 암호를 통해 키를 생성합니다. 4. ECB 모드 비활성화, GCM과 같은 인증 암호화 모드를 채택하고 각 암호화에 고유 한 IV를 사용하고 민감한 민감한 IV를 시간에 사용하십시오.

runeApplicationOrCommandAsAdMinistratorByright-Clicking andSelecting "RunasAdMinStrator"TONESUREELEVATEDPRIVILEGESERANTED.2.CHECKUSERACCOUNTCONTROL (UAC) SETCTINGSBYSERCHINGFORUACINTHARTMENUANDSTITTINGTHETEDEFAULLEVEL (SecondFrff

패턴 클래스는 정규 표현식을 컴파일하는 데 사용되며 매칭 클래스는 문자열에서 일치하는 작업을 수행하는 데 사용됩니다. 이 둘의 조합은 텍스트 검색, 일치 및 교체를 실현할 수 있습니다. 먼저 Pattern.comPile ()을 통해 Pattern Object를 작성한 다음 Matcher () 메서드를 호출하여 매치 자 인스턴스를 생성하십시오. 그런 다음 matches ()를 사용하여 전체 문자열 일치를 판단하고 ()를 판단하고 ()를 찾으려면 하위 시퀀스, replaceall () 또는 replacefirst ()를 대체 할 수 있습니다. 정규에 캡처 그룹이 포함 된 경우 Nth 그룹 내용은 그룹 (N)을 통해 얻을 수 있습니다. 실제 응용 프로그램에서 반복적 인 컴파일 패턴을 피하고 특수 문자 탈출에주의를 기울이고 필요에 따라 일치하는 패턴 플래그를 사용하고 궁극적으로 효율적으로 달성해야합니다.
![LOL 게임 설정이 닫힌 후 저장되지 않음 [수정]](https://img.php.cn/upload/article/001/431/639/175597664176545.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
ifLeagueOfleGendsSetSetsAren'TSAVING, TryTheSTEPS : 1.RUNTHEGAMEASADMINSTRARTR.2.GRANTFULLDORMISSIONSTOTHELEAGUEFLEGENDSDIRECTORY.3.EDITANDENSUREGAME.CFGISN'TREAD-ANLY.4.DISABLECLOUDSINCFORTHEMAME.REPAMETEGOMETHOMETHOMETHOMETHOMETHOMETHOLEGOLEGOLEGOLEGOLEGOLEGOLEGOLEGOLETHOME.
!['Java는 인식되지 않습니다'CMD에서 오류 [3 가지 간단한 단계]](https://img.php.cn/upload/article/001/431/639/175588500160220.jpg?x-oss-process=image/resize,m_fill,h_207,w_330)
ifjavaisnotrecenizedIncmd, 보장, setthejava_homevariabletothejdkpath, andaddthejdk'sbinfoldertothesystempath.restartcmdandrunjava-versiontoconfirm.
