Results 1 to 8 of 8
 05112010, 02:46 PM #1Senior Member
 Join Date
 May 2010
 Posts
 112
 Rep Power
 0
Java course work beginner's leve,Help
Hi Friends,
This is my first time posting in this form and first time posting with regards to Java.I am new learner of Java.And I need help please.
Write a JAVA program that asks for a number (for instance 154).The program
has to display the digits of the number in reverse order.
for instance: 451
I hope you got the question,another example is suppose I entered 234 as the input on the program.The program has to display 432.
The program below should give u clues.I tried many times but I was unsuccessful.
/*
* File: DigitSum.java
* 
* This program sums the digits in a positive integer.
* The program depends on the fact that the last digit of
* a integer n is given by n % 10 and the number consisting
* of all but the last digit is given by the expression n / 10.
*/
import acm.program.*;
public class DigitSum extends ConsoleProgram {
public void run() {
println("This program sums the digits in an integer.");
int n = readInt("Enter a positive integer: ");
int dsum = 0;
while (n > 0) {
dsum += n % 10;
n /= 10;
}
println("The sum of the digits is " + dsum);
}
}
Thank you in advance.
 05112010, 02:52 PM #2
 Join Date
 Sep 2008
 Location
 Voorschoten, the Netherlands
 Posts
 14,422
 Blog Entries
 7
 Rep Power
 28
All you have to do is change this line:
Java Code:int dsum = 0;
Java Code:String dsum = "";
kind regards,
JosLast edited by JosAH; 05112010 at 02:58 PM.
 05112010, 02:52 PM #3
Uhm, you posted the wrong code, that sums up the digits, but does not reverse anything.
Math problems? Call 1800[(10x)(13i)^2][sin(xy)/2.362x]
The Ubiquitous Newbie Tips
 05112010, 08:18 PM #4
Could this work?
Break String to Char Array, then print reverse?:rolleyes: ~ Sno ~ :rolleyes:
'~ B.S. Computer Science ~'
 05172010, 04:31 PM #5Senior Member
 Join Date
 May 2010
 Posts
 112
 Rep Power
 0
can anybody solve it?
 05172010, 04:52 PM #6
Jos has solved it 12 days ago.
Math problems? Call 1800[(10x)(13i)^2][sin(xy)/2.362x]
The Ubiquitous Newbie Tips
 05172010, 04:59 PM #7Senior Member
 Join Date
 May 2010
 Posts
 112
 Rep Power
 0
Thank you for the replay phhein.Has it been really solved ? i need to try it yet.cheers.
 05172010, 05:14 PM #8Senior Member
 Join Date
 May 2010
 Posts
 112
 Rep Power
 0
Similar Threads

Trying to get JAVA to work with SQLite
By mark8569 in forum JDBCReplies: 3Last Post: 04252009, 01:42 AM 
Just how do I get Java to actually work?
By MickY G in forum New To JavaReplies: 5Last Post: 11192008, 03:50 AM 
What are applet and how its work in java?
By pawankumarom in forum New To JavaReplies: 7Last Post: 09052008, 05:26 PM 
Beginner's Problem on Loop/If statement
By obdi in forum New To JavaReplies: 2Last Post: 07072008, 01:41 AM 
Ho to work with enumerations in java
By zizou147 in forum Advanced JavaReplies: 0Last Post: 03222008, 12:53 PM
Bookmarks