Question

in java .. how can i order 4 digit number like(3427) to(7432) ...hint: we can( not...

in java .. how can i order 4 digit number like(3427) to(7432) ...hint: we can( not )use an array :( never ever!

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

Program :

import java.util.Scanner;
public class Main
{
   public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   int rem,rev=0;
   System.out.println("Enter a number:");
   int n = sc.nextInt(); //read the value from keyboard
   while(n!=0){
   rem = n% 10; //to find the remainder
rev = rev * 10 + rem; // multiply the rev with 10 and add remainder
n=n/ 10; //reduce digit by number (ex:3472 to 347)
   }
   System.out.println("Reverse of the digit :"+rev);
   }
}
Screenshot of the program :

Add a comment
Know the answer?
Add Answer to:
in java .. how can i order 4 digit number like(3427) to(7432) ...hint: we can( not...
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
  • If we create a 4 digit pin number using only the digits {0,1,2,3,4}, how many unique...

    If we create a 4 digit pin number using only the digits {0,1,2,3,4}, how many unique 4 digit pin numbers can we make?

  • JAVA program. I have created a game called GuessFive that generates a 5-digit random number, with...

    JAVA program. I have created a game called GuessFive that generates a 5-digit random number, with individual digits from 0 to 9 inclusive. (i.e. 12345, 09382, 33044, etc.) The player then tries to guess the number. With each guess the program displays two numbers, the first is the number of correct digits that are in the proper position and the second number is the sum of the correct digits. When the user enters the correct five-digit number the program returns...

  • How many 4-digit numbers can be formed using only the digits {1,2,3} if repetition is allowed...

    How many 4-digit numbers can be formed using only the digits {1,2,3} if repetition is allowed and the number must contain the digit 3 somewhere. Hint: it may be easier to first count the numbers that don't contain the digit 3.

  • Using Java, how would you test if a int number contains the digit 8 using recursive...

    Using Java, how would you test if a int number contains the digit 8 using recursive functions? public static boolean isLucky(int number)

  • can someone please help me with this. I need to use java. Recursion Write and run...

    can someone please help me with this. I need to use java. Recursion Write and run a program that reads in a set of numbers and stores them in a sequential array. It then calls a recursive function to sort the elements of the array in ascending order. When the sorting is done, the main function prints out the elements of the newly sorted array Hint: How do you sort an array recursively? Place the smallest element of the array...

  • 2.29 Random Phone Number (Java) Write a program that creates and prints a random phone number...

    2.29 Random Phone Number (Java) Write a program that creates and prints a random phone number of the form 668-555-xxxx where xxxx is a 4-digit randomly generated number. Include the dashes in the output. Think through how you can guarantee a 4-digit number. Your output should look like: A random phone number: 678-555-1234 Given: import random number public class PhoneNumbers { //----------------------------------------------------------------- // Produces a random phone number of the form 678-555-xxxx. //----------------------------------------------------------------- } }

  • (Java) how can i remove a element of a array if it contains a specific word?...

    (Java) how can i remove a element of a array if it contains a specific word? —> ( ex: word= hi) , so any element that has “hi” in it will be removed. and then recreate the array with the remaining elements?

  • I need you guys help with my Java Class( use netbean if you can, thank a...

    I need you guys help with my Java Class( use netbean if you can, thank a lot ). Please help me out, I may need full working code Question: An array A contains n−1 unique integers in the range [0,n−1], that is, there is one number from this range that is not in A. Design an O(n)-time algorithm for finding that number. You are only allowed to use O(1) additional space besides the array A itself. DO NOT SORT THE...

  • 2) (5pts) A 3-digit number will be formed using the digits 1, 2, 3, 4, 5;...

    2) (5pts) A 3-digit number will be formed using the digits 1, 2, 3, 4, 5; using each digit only once. a) How many possible 3-digit numbers are possible? TOTAL: b) Assume three of the digits are randomly chosen and randomly permuted in order to form the 3-digit number. Then each of the possible 3-digit numbers in part a) are equally likely. Find the probability that the 3-digit number ends up being an even number greater than or equal to...

  • 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