I am not clear about your Odd number. The way this code works is (it is not a Java specific algorithm) Eg. input =2345 first time in the while loop rev=5 input=234 second time rev=5*10+4=54 input=23 third time rev=54*10+3 input=2 fourth time rev=543*10+2 input=0
So the reversed number is 5432. If you just want only the odd numbers in the reversed number then. The code is:
while (input != 0) { last_digit = input % 10; if (last_digit % 2 != 0) { reversedNum = reversedNum * 10 + last_digit; } input = input / 10; }
Related Posts:
- What does value & 0xff do in Java?
- Declaring an unsigned int in Java
- What is the maximum value for an int32?
- max value of integer
- How do I generate random integers within a specific range in Java?
- How do I generate random integers within a specific range in Java?
- Signed versus Unsigned Integers
- How can I convert a character to a integer in Python, and viceversa?
- How can I properly compare two Integers in Java?
- How to convert integer to string in C?
- How does Python manage int and long?
- How to check whether a int is not null or empty?
- Declaring an unsigned int in Java
- Exception in thread “main” java.lang.NumberFormatException: For input string: “S”
- int cannot be converted to string?
- How can I convert integer into float in Java?
- How to implement infinity in Java?
- Converting String Array to an Integer Array
- How to check if the value is integer in java?
- Converting a string to an integer on Android
- Reading and printing an integer in mips
- Is there any difference between 1U and 1 in C?
- Convert an integer to an array of digits
- How can I check if a value is of type Integer?
- “Integer number too large” error message for 600851475143
- Cannot invoke toString() on the primitive type int
- Why int[] a = new int[1] instead of just int a?
- Why int[] a = new int[1] instead of just int a?
- Why cannot cast Integer to String in java?
- How to convert integers to characters in C?
- Convert int to ASCII and back in Python
- How do I “decompile” Java class files? [closed]
- How do I compare strings in Java?
- Is Java “pass-by-reference” or “pass-by-value”?
- Could not reserve enough space for object heap
- What does “Could not find or load main class” mean?
- What is null in Java?
- What is an illegal reflective access?
- Convert Set to List without creating new List
- Alternative to itoa() for converting integer to string C++?
- Can I catch multiple Java exceptions in the same catch clause?
- How to get the current date/time in Java
- What is the use of printStackTrace() method in Java?
- How do I limit the number of decimals printed for a double?
- Please initialize the log4j system properly warning
- How to convert jsonString to JSONObject in Java
- how to iterate in List
- > in java and set their values as we do in a normal int a[i][j] matrix type [duplicate]
- java.lang.NullPointerException: Attempt to invoke virtual method on a null object reference
- Java – Best way to print 2D array?
- Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
- How to update a value, given a key in a hashmap?
- How to schedule a periodic task in Java?
- How to create an empty array?
- How to decompile a whole Jar file?
- How to fix org.hibernate.LazyInitializationException – could not initialize proxy – no Session
- Find how many connected groups of nodes in a given adjacency matrix
- Java dynamic array sizes?
- Java – Best way to print 2D array?
- “cannot find symbol: method” but the method is declared
- How do I set the proxy to be used by the JVM
- Where to get the tools.jar to use with the Java 8 jdk early release
- What are the possible values of the Hibernate hbm2ddl.auto configuration and what do they do
- How to fix the Hibernate “object references an unsaved transient instance – save the transient instance before flushing” error
- InvocationTargetException when running a javafx program
- PersistentObjectException: detached entity passed to persist thrown by JPA and Hibernate
- How do I use the JAVA_OPTS environment variable?
- javax.xml.bind.UnmarshalException: unexpected element (uri:””, local:”Group”)
- Enqueue, Dequeue and ViewQueue in Java
- org.xml.sax.SAXParseException: Content is not allowed in prolog
- Running Command Line in Java
- Working Soap client example
- Simple Dropdown menu in Java
- repaint() Method in Java
- TicTacToe AI Java
- Java GUI: about getContentPane( ) method and content
- How to convert an Instant to a date format?
- equivalent to push() or pop() for arrays?
- JaxbRepresentation gives error “doesnt contain ObjectFactory.class or jaxb.index”
- How do I fix a NoSuchMethodError?
- What is the Java equivalent for LINQ?
- “Expression expected” and “Cannot find symbol” error
- Android Studio ERROR: Cannot resolve symbol ‘View’
- Static Initialization Blocks
- “Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar” when starting the Scala interpreter
- Swing/Java: How to use the getText and setText string properly
- java eclipse red exclamation mark
- Java FileOutputStream Create File if not exists
- Configure active profile in SpringBoot via Maven
- How to display hexadecimal numbers in C?
- Is there any way to program Java on Visual Studio 2015
- Keylistener not working for JPanel
- the getSource() and getActionCommand()
- Failed to install android-sdk: “java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema”
- Exception is never thrown in body of corresponding try statement
- Could not transfer artifact org.apache.maven.plugins:maven-surefire-plugin:pom:2.7.1 from/to central (http://repo1.maven.org/maven2)
- Using while loop as input validation [duplicate]
- java -version and javac -version showing different versions
- when spring boot startup,throw out the “method names must be tokens” exception
- How to get javax.comm API?
- how to convert exe file to .jar file? [duplicate]