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
  • 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.

  • 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...

  • 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...

  • 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...

  • How would the Java Program look like if I wanted to place the following values in...

    How would the Java Program look like if I wanted to place the following values in the oder that they would be in after being bulk insterted into a heap for Heap sort and how would the heap look like after three deleteMin() commands? These would be some example values: 9 5 8 2 4 3 1 7 6 0. ( place values that were removed using a delete min at the start in order that they were removed/

  • 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 We did in lecture, and explain your answer briefly. Problem 4: Sorting practice 14 points;...

    Java We did in lecture, and explain your answer briefly. Problem 4: Sorting practice 14 points; 2 points for each part individual-only Important: When answering these questions, make sure to apply the versions of these algorithms that were discussed in lecture. The Java code for each algorithm can be found in our Sort class. Given the following array: {14, 7, 27, 13, 24, 20, 10, 33 1. If the array were sorted using selection sort, what would the array look...

  • java classes. If we want to store primitive data types in an ArrayList object, then we...

    java classes. If we want to store primitive data types in an ArrayList object, then we should use accessor mutator static wrapper QUESTION 10 What is the purpose of this code? for (int i = 0; i < arrayName.length; i++ X for (int j - 0) < arrayNamelij length; j++ X Il process element arrayName[001 ) - it is the general pattern for processing the elements of a two-dimensional array called arrayName in column- first row second order It is...

  • We use bluej for our JAVA program. If you can help id greatly appreciate it. Create...

    We use bluej for our JAVA program. If you can help id greatly appreciate it. Create a new Java program called Flip. Write code that creates and populates an array of size 25 with random numbers between 1-50. Print the array. Print array in reverse.

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