(2)  Reverse a number using while Loop Write a java code that prompts the user to input a non-negative integer and then it will reverse the same number using a while loop. For example, if the input number is 25 the output should be 52.             Sample input and output:             Example 1:             Input: 25      Output: 52             Example 2:             Input: 123      Output: 321             Example 3:             Input: 3      Output: 3

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter3: Assignment, Formatting, And Interactive Input
Section3.4: Program Input Using Cin
Problem 9E
icon
Related questions
Question

Language: JAVA  

PLEASE DO QUESTIONS 2 AND 3 ONLY

  • PIN Lockout

Write a code to enter a 4-digit PIN as an integer, and check if the pin is valid (the valid PIN is 1234). If the PIN is not valid print an error message “INCORRECT PIN. TRY AGAIN.” and let the user enter the PIN again. But the user only has 3 tries to enter the correct PIN. If the user enters the wrong PIN for his/her 3 tries then print “YOU HAVE RUN OUT OF TRIES. ACCOUNT LOCKED.”  And if the user enters the valid PIN within the 3 tries print “PIN ACCEPTED. YOU NOW HAVE ACCESS TO YOUR ACCOUNT.”

Use a while loop to prompt the user to enter a valid PIN. Do not forget to print a prompt for the user asking to enter the PIN.

Create a class named PinLockout which will have the main method. All your code goes inside the main method.

            Sample input and output:

            Sample 1:

ENTER YOUR PIN: 2345

INCORRECT PIN. TRY AGAIN.

ENTER YOUR PIN: 2356

INCORRECT PIN. TRY AGAIN.

ENTER YOUR PIN: 7564

YOU HAVE RUN OUT OF TRIES. ACCOUNT LOCKED.

 

Sample 2:

ENTER YOUR PIN: 2345

INCORRECT PIN. TRY AGAIN.

ENTER YOUR PIN: 1234

PIN ACCEPTED. YOU NOW HAVE ACCESS TO YOUR ACCOUNT.

 

 

 

 

 

 

 

 

 

(2)  Reverse a number using while Loop

Write a java code that prompts the user to input a non-negative integer and then it will reverse the same number using a while loop. For example, if the input number is 25 the output should be 52.

            Sample input and output:

            Example 1:

            Input: 25

     Output: 52

            Example 2:

            Input: 123

     Output: 321

            Example 3:

            Input: 3

     Output: 3

           

 

 

 

(3) Palindrome Number 

Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward. For example, 12321 is a palindrome number.

Follow up: Could you solve it without converting the integer to a string?

Create a class named Palindrome which will contain the main method. All your code goes in the main method. 

            Sample Input and output:

Example 1:

Input: x = 121

Output: true

Example 2:

Input: x = -121

Output: false

Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome

Example 3:

Input: x = 10

Output: false

Explanation: Reads 01 from right to left. Therefore it is not a palindrome.

 

Example 4:

Input: x = -101

Output: false

 

Example 5:

Input: x = 3

Output: true

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT