473,396 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Reverse numbers entered

I am a beginning java student. I have taken C++ before, but I am not proficient at it yet. I found this web site by browsing, looking for assistance to complete a java program I have been working on this evening. One day I hope to become a java programer and provide this same kind of help for someone else.

I need help in getting this program to reverse any number entered.
Expand|Select|Wrap|Line Numbers
  1.  import java.util.*;
  2. public class ReverseNumbers
  3. {
  4.  
  5.     static Scanner console = new Scanner(System.in);
  6.     public static void main(String[] args)
  7.     {
  8.         int counter;
  9.         int sum;
  10.         int num;
  11.         String numString;
  12.  
  13.  
  14.         System.out.println("Enter the number of integers to be added: ");
  15.  
  16.         System.out.flush();
  17.         num = console.next();                //get the next number
  18.         System.out.println();
  19.  
  20.             sum = 0;
  21.             for (counter = 0; counter <=num; counter++)
  22.             sum = sum + num;                //add the number to sum
  23.  
  24.                 {    
  25.                     System.out.print("The sum of the integer is: " + sum);
  26.                     System.out.println(sum + " ");
  27.                 }
  28.  
  29.             numString = num;
  30.             for(int i = numString; i>= numString; i--)
  31.                 {
  32.  
  33.                     System.out.print(i + "");
  34.                     System.out.println();
  35.                 }
  36.  
  37.  
  38.  
  39.     }
  40.  
  41. }
May 15 '07 #1
4 5711
MMcCarthy
14,534 Expert Mod 8TB
This question has been moved to Java forum from the Introductions forum.

ADMIN
May 15 '07 #2
prometheuzz
197 Expert 100+
I am a beginning java student. I have taken C++ before, but I am not proficient at it yet. I found this web site by browsing, looking for assistance to complete a java program I have been working on this evening. One day I hope to become a java programer and provide this same kind of help for someone else.

I need help in getting this program to reverse any number entered.
OK, what is the problem? (unexpected output? compiler errors? runtime errors?)
May 15 '07 #3
rsrinivasan
221 100+
hi,

I don't know what problem you have.

If u have errors in this program,

replace your code with my code and run it...

Expand|Select|Wrap|Line Numbers
  1. numString = String.valueOf(num);
  2. for(int i = numString.length()-1; i>= 0; i--)
  3. {
  4. System.out.print(numString.charAt(i) + "");
  5. }
thanks,
May 15 '07 #4
Thank you. Your code worked. I was trying to print an int value instead of a string value of "i."

hi,

I don't know what problem you have.

If u have errors in this program,

replace your code with my code and run it...

Expand|Select|Wrap|Line Numbers
  1. numString = String.valueOf(num);
  2. for(int i = numString.length()-1; i>= 0; i--)
  3. {
  4. System.out.print(numString.charAt(i) + "");
  5. }
thanks,
May 15 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Artemis Fowl | last post by:
when i used bitset<> to accept data from the user, much to my surprise, i got the wrong answer. After a bit of fiddling, figured out that the data being entered was being consumed in reverse. I...
4
by: Earl | last post by:
I'm curious if there are others who have a better method of accepting/parsing phone numbers. I've used a couple of different techniques that are functional but I can't really say that I'm totally...
15
by: Fabio Cannizzo | last post by:
Is it possible to do something similar to the STL iterators, i.e. to execute a foreach loop in reverse order? Thanks, Fabio
41
by: rick | last post by:
Why can't Python have a reverse() function/method like Ruby? Python: x = 'a_string' # Reverse the string print x Ruby: x = 'a_string' # Reverse the string
5
by: dav3 | last post by:
I have almost completed a monster assignment on sorting algorithms (quick, insertion and selection) using c++ but I am lost on one part of the assignment. I have to generate a random list of numbers...
7
by: analoveu | last post by:
I wanna print the following shape 1 121 12321 1234321 12321 121 1
1
by: rgtidwell | last post by:
I know this code is wrong, and I am paying the price now for focusing on Linear last semester during the first half of C++, but I am trying to figure this out. Can anyone help? I want to make sure:...
8
by: blazo | last post by:
its here why isit like that #include <stdio.h> int z; int y; void reverse_order(int x,int y) { for (y = 9; y >=0; --y) { printf("%d \t",x);
3
by: powerej | last post by:
writing a program that asks how many numbers the users want to enter, then input an integer for the amount of numbers said, output: number of integers entered, sum of them, average of them, maximum...
4
by: beginers of c | last post by:
hai friends see i have to get numbers in this manner 3 4 5 6 7 8 9 ok.And also my numbers should not be larger than 9.so for each number the condition has to be checked if it's great than 9 ,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.