i wrote very simple code for reversing integer digits. but when i compile it, i get message as

----jGRASP exec: javac -g C:\Program Files\Java\jdk1.6.0_23\bin\ReverseDigit.java
---- at: Mar 14, 2011 7:58:58 PM

----jGRASP wedge: pid for wedge is 4920.
----jGRASP wedge2: pid for wedge2 is 1788.
----jGRASP wedge2: CLASSPATH is ".;;.;C:\Program Files (x86)\QuickTime\QTSystem\QTJava.zip;C:\Program Files (x86)\jGRASP\extensions\classes".
----jGRASP wedge2: working directory is [C:\Program Files\Java\jdk1.6.0_23\bin] platform id is 2.
----jGRASP wedge2: actual command sent ["C:\Program Files\Java\jdk1.6.0_23\bin\javac.exe" -g "C:\Program Files\Java\jdk1.6.0_23\bin\ReverseDigit.java"].
----jGRASP wedge2: pid for process is 5984.

----jGRASP wedge2: exit code for process is 0.
----jGRASP: operation complete.

The code runs. but does not give any output.
I put some out.print statements to find out what's happening. my program does not take value inputed. my code is:

import java.util.Scanner;

public class ReverseDigit
 public static void main( String args[] ) 
     int number,newnumber1;
     Scanner input = new Scanner( System.in );
	  System.out.print( "Enter the number to be reversed\n" );
	  number = input.nextInt();
	  newnumber1 = reverseInt(number);
	  System.out.printf( "::: ",number );
	  System.out.printf( "The reversed number is: ",newnumber1 );

   public static int reverseInt(int num1)
     int digit1,digit2,digit3,digit4;
	  int newnumber;
	 digit1 = num1/1000;
    digit2 = num1/100 - digit1*10;
    digit3 = num1/10 - digit1*100 - digit2*10;
    digit4 = num1 - digit1*1000 - digit2*100 - digit3*10;
	 newnumber = (digit4 * 1000) + (digit3 * 100)+ (digit2 * 10) + digit1;
	 System.out.printf( ": ",newnumber );
	 return newnumber;

and the output i get is:

Enter the number to be reversed
: ::: The reversed number is:
what could be the problem?

Recommended Answers

All 6 Replies

It's doing exactly what you asked for.
You didn't ask for what you wanted, though.

System.out.printf( "::: ",number );

The format string here doesn't reference a variable, so it doesn't use number for anything. Try

System.out.printf( "%d ",number );

You might try

System.out.printf( "%d \n",number );

if you want a line break.

You might also try reading the printf documentation here or here or here

replace the comma in line 16 with a plus sign(+) and also delete line 30 since you are returning the result i don't thing it is ok to output it
System.out.printf( "The reversed number is: "+ newnumber1 );

+ concatenation would work, I suppose, in line 16, but it's not what you want in a printf(). printf is for formatted output, you wouldn't want to just cat the variables onto the end of it. For that, you want println or print, probably println.

@ jon, %d really works. so stupid of me!!! :-)
@ sam, +concatenation also works as well.
well, I added line 30 just to check if it returns value in the method or not.
Thank you guys.

do you have any idea, why it shows above message while compiling? i noticed that it shows for other programs also.It was not showing it before.

It's just telling you that it told the compiler to compile, and it did. An exit code of 0 typically indicates success - this allows you to use non-zero exit codes as error messages.

Thanks Jon.
I didn't see that message before.That's why was wondering about it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.