Question

(use the JOptionPane methods for input and output) Write a java application that prompts the user...

(use the JOptionPane methods for input and output)

Write a java application that prompts the user to input an integers x.

Then the program should call the method isAutomorphic to check if the integer x is automorphic*or not. At the end the program should output a message to indicate if x is automorphic or not

*In Mathematics, an automorphic number is a number that ends with the same digit that its square ends with.

For Example:

762 = 5776    è  (76 is automorphic since it ends with 6 and its square 5776 ends with 6 as well)

52 = 25         è  (5 is automorphic since it ends with 5 and its square 25 ends with 5 as well)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// Java program to input an integer and check if it is an automorphic number or not
import javax.swing.JOptionPane;


public class Automorphic {
   // method that returns true if x is an automorphic number else false
   public static boolean isAutomorphic(int x)
   {
       // An automorphic number is a number that ends with the same digit as the square of that number ends
       // a%b returns the remainder when a is divided by b
       // if last digit of x = last digit of square of x, then it is automorphic else it is not automorphic
       return((x%10) == ((x*x)%10));
              
   }
     
   public static void main(String[] args) {
      
       String x;
       // input of integer
       x = JOptionPane.showInputDialog(null,"Enter an integer: ");
      
       // convert x to integer and check if it is automorphic or not and display the result
       if(isAutomorphic(Integer.parseInt(x)))
           JOptionPane.showMessageDialog(null,x+" is an automorphic number");
       else
           JOptionPane.showMessageDialog(null,x+" is not an automorphic number");
      
}
}

//end of program

Output:

Add a comment
Know the answer?
Add Answer to:
(use the JOptionPane methods for input and output) Write a java application that prompts the user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design a Java application that prompts the user to input the x- and y-coordinates of a...

    Design a Java application that prompts the user to input the x- and y-coordinates of a point in a Cartesian plane. The program then should output a message indicating whether the point is the origin, or is located on the x (or y) axis, or appears in a particular quadrant. For example: (0, 0) is the origin (4, 0) is on the x-axis (0, -3) is on the y-axis (-2, 3) is in the second quadrant The numbering of the...

  • Write code that prompts the user to input a number. The program should then output the...

    Write code that prompts the user to input a number. The program should then output the number and a message saying whether the number i "Positive, "Negative" or "Zero". It should further output whether the number is odd or even (zero is counted as even) For example:

  • java Write an application that will show 5 different messages (no input, 5 types: error message,...

    java Write an application that will show 5 different messages (no input, 5 types: error message, question message, information message, warning message and plain message). Use the welcome.java example from lecture slides. You should end up with just one file. Icon Code IDE Value JOptionPane.PLAIN MESSAGE JOptionPane.ERROR MESSAGE No icon -1 X 0 JOptionPane.INFORMATION MESSAGE 1 JOptionPane.WARNING MESSAGE 2 JOptionPane QUESTION MESSAGE 3 Write an application that will show 5 different messages (no input, 5 types: error message, question message,...

  • use  JOptionPane to display output Can someone please help write a program in Java using loops, not...

    use  JOptionPane to display output Can someone please help write a program in Java using loops, not HashMap Test 1 Grades After the class complete the first exam, I saved all of the grades in a text file called test1.txt. Your job is to do some analysis on the grades for me. Input: There will not be any input for this program. This is called a batch program because there will be no user interaction other than to run the program....

  • in java 3) Sum. Write a program that prompts the user to read two integers and...

    in java 3) Sum. Write a program that prompts the user to read two integers and displays their sum. Your program should prompt the user to read the number again if the input is incorrect.

  • Write a java application to input 2 positive integers X and Y such that X is...

    Write a java application to input 2 positive integers X and Y such that X is less than Y. Then the program should do the following: 1. Output the sum of even integers between 1 and X. 2. Output the average of odd integers between 1 and Y. 3. Output the common divisors of X and Y.

  • Java: Write a program that prompts the user to enter integers in the range 1 to...

    Java: Write a program that prompts the user to enter integers in the range 1 to 50 and counts the occurrences of each integer. The program should also prompt the user for the number of integers that will be entered. As an example, if the user enters 10 integers (10, 20, 10, 30, 40, 49, 20, 10, 25, 10), the program output would be: 10 occurs 4 times 20 occurs 2 times 25 occurs 1 time 30 occurs 1 time...

  • in java Write an application that: 1. Prompts the user for a number of trials to...

    in java Write an application that: 1. Prompts the user for a number of trials to perform (I will call this "N"). This operation should be type-safe for integers. 2. Simulates N trials of rolling two dice and finding the sum. 3. Uses an array to keep track of how many times each outcome has been rolled (you do not need to keep track of the actual rolls themselves). 4. Computes the percentage of the total number of rolls for...

  • Write a Java application that prompts the user for pairs of inputs of a product number...

    Write a Java application that prompts the user for pairs of inputs of a product number (1-5), and then an integer quantity of units sold (this is two separate prompts for input values). You must use a switch statement and a sentinel-controlled loop (i.e. a loop that stops execution when an out of range value, such as -1, is input). All 15 items below are for a single purchase. There are five sets of inputs as follows: Product 1    1...

  • java Write an application that input a number from the user and checks if all digits...

    java Write an application that input a number from the user and checks if all digits are prime numbers using method prime. The number entered can be of any size. If all digits are prime your program should stop. Use do/while for reading the input and any loop format to test if the number is prime. When checking the prime numbers don’t use an if to check numbers from 1 – 9; you need to find an algorithm to check...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT