Question

java create an array of n intergers. ask the user for entry of an integer n....

java

create an array of n intergers. ask the user for entry of an integer n. populate this array with first n palindromes.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any problem with the code feel free to comment.

Program

import java.util.Arrays;
import java.util.Scanner;

public class Test{
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
      
       System.out.print("Enter the n: ");
       int n = sc.nextInt();sc.nextLine();
      
       int[] ar = new int[n];
       int value=0;
      
       for(int i=0; i<n; i++) {//primary loop runs till n
           while(true) {//infinte loop runs till palindrom number is found
               value++;
               if(checkPalidrome(value)) {
                   ar[i] = value;
                   break;
               }
           }

       }
      
       System.out.println("First "+n+" Palindromic numbers ");
       System.out.println(Arrays.toString(ar));
       sc.close();
   }
  
   private static boolean checkPalidrome(int num) {
       int rev=0, temp=num;
       //checking if the number is palindrome or not
       while(num>0) {
           rev = rev * 10 + num%10;
           num/=10;
       }
       if(rev == temp)
           return true;
       else
           return false;
   }
}

Output

Add a comment
Know the answer?
Add Answer to:
java create an array of n intergers. ask the user for entry of an integer n....
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
  • Create a java program that with an integer array that has ten numbers in it. Ask...

    Create a java program that with an integer array that has ten numbers in it. Ask the user for an integer. Search your array and if found it tell them at what position it was found. If not found tell them the number was not found.

  • JAVA Ask the user for integers. If the user did not enter an integer, ask again....

    JAVA Ask the user for integers. If the user did not enter an integer, ask again. (Type Safe Input) Keep a running total of the intergers entered (sum). Once the user enters 0, stop looping. Print the sum of all the numbers. Do not use try-catch. EXAMPLE OUTPUT: Enter an integer, 0 to stop> [fasdfsa] Invalid input. Enter an integer, 0 to stop> [231.342] Invalid input. Enter an integer, 0 to stop> [1] Enter an integer, 0 to stop> [2]...

  • In Java create an integer array named dice1 with a size of 10. Populate each array...

    In Java create an integer array named dice1 with a size of 10. Populate each array location with a roll of a six-sided die (hint: an int value of 1 through 6). Print the array out using an enhanced for loop. Sample output: Question 1 dice1 = 1 1 6 2 3 5 1 5 4 5

  • in java please Create an array of characters. Ask the user to enter two characters. Tell...

    in java please Create an array of characters. Ask the user to enter two characters. Tell the user which character occurs more frequently For example, suppose the array contains (a, b, c, d, 8, 2, e, e, f, g and the user enterse and then the program will say that occurs more frequently thanL Bonus: Display a list of all characters in the array with their frequencies. Each value should appear only once For example for the array(a, b, c,...

  • Java 1. Create a 1D array of 4096 Unique random integer numbers of 1 to 5...

    Java 1. Create a 1D array of 4096 Unique random integer numbers of 1 to 5 digits. Of those numbers give me the following information: - Mean , Mode, Median, Range. - Five times, ask the user for a number within the range (from above) and record the time to find the number in the range. (Loop count) 2. Using a any sort algorithm, build sorted 2D array of random numbers (1 TO 5 digits ) with the x direction...

  • Write a short program in Java that asks the user for an integer. Then ask the...

    Write a short program in Java that asks the user for an integer. Then ask the user for a letter. Print out the letter followed by the integer.

  • write a java program Accept a positive integer n from keyboard and then create an array...

    write a java program Accept a positive integer n from keyboard and then create an array or arraylist containing n random elements within the range [-n,n). Print out the random array or arraylist, and then find out and print out the number of inversions and the maximum subarray (index range of the maximum subarray along with the maximum subarray sum) in the array or arraylist using divide and conquer, respectively. For example, suppose we accept integer 6 from keyboard, then...

  • Write a program which will take a list of integer number from the user as input...

    Write a program which will take a list of integer number from the user as input and find the maximum and minimum number from the list. First, ask the user for the size of the array and then populate the array. Create a user define function for finding the minimum and maximum numbers. You have to use pointer variables for solving the problem. Finally, you need to print the entire list along with the max and min numbers ALSO NEED:...

  • Create two java programs. The first will ask the user to enter three integers. Once the...

    Create two java programs. The first will ask the user to enter three integers. Once the three integers are entered, ask the user to enter one of three functions. The “average” if they want the average of the three numbers entered, enter “min” if they want the minimum and “max” if they want the maximum. Display the answer. Ask the user if they want to calculate another function for the three numbers. If so, loop and ask what function they...

  • Design a Java program that asks the user to enter an integer number n and then...

    Design a Java program that asks the user to enter an integer number n and then generates an array of that many random points (x, y) with x- and y-coordinates in the range between 0 and 100. After this the program must ask the user to enter two diagonal points (x_1, y_1) and (x_2, y_2) of a rectangle with sides parallel to the coordinate axis (see the image below, where possible pairs of diagonal points are shown in red color)....

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
ADVERTISEMENT