sum « Number « Java Data Type Q&A





1. Make a negative number positive in Java    stackoverflow.com

I'm sure this is a very simple question! I have a Java method in which I'm summing a set of numbers. However, I want any negatives numbers to be treated as ...

2. Getting N random numbers that the sum is M    stackoverflow.com

I want to get N random numbers that the sum of them is a value. For example, let's suppose I want 5 random numbers that their sum is 1 Then, a valid possibility ...

3. Java sum 2 negative numbers    stackoverflow.com

I'm trying to convert a function in java to pl/pgsql, and one problem that I found is when I'm trying to sum 2 negative numbers, and a get a positive number, ...

4. How can I find the sum of two numbers which are in String variables?     stackoverflow.com

In this code fragment i can't sum a and b :

String a= txtnum1.getText();
String b= txtnum2.getText(); 
JOptionPane.showMessageDialog(null,a+b);
...because a and b defined by String so this code work like this if i'll give a=10 ...

5. Sum of numbers under 10,000 that are multiples of 3, 5 or 7 in Java    stackoverflow.com

I know how to get the program to add up the sums of the multiple for each of 3, 5 and 7, but I'm not sure how I'd get the program ...

6. True-way solution in Java: parse 2 numbers from 2 strings and then return their sum    stackoverflow.com

Quite a stupid question. Given the code:

public static int sum(String a, String b) /* throws? WHAT? */ {
  int x = Integer.parseInt(a); // throws NumberFormatException
  int y = Integer.parseInt(b); ...

7. How do I add input numbers eliminating the ones duplicated?    stackoverflow.com

For example my input numbers are: 10 10 and 15. The second input will be ignored since it is already duplicated. So the sum would be 10+15 - 25. How do ...

8. Find the sum of the digits in the number 100! (My while loop would not stop, please help.)    stackoverflow.com

I've been trying to solve Problem 20 in Project Euler:

n! means n (n 1) ... 3 * 2 * 1 For example, 10! = ...

9. help with getting number sum    bytes.com

I wrote this program that reads a txt file named books that contains a list of books and prices. My program arranges the file with the book and price on the ...





10. Sum of amicable numbers    coderanch.com

Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n). If d(a) = b and d(b) = a, where a b, then a and b are an amicable pair and each of a and b are called amicable numbers. For example, the proper divisors of 220 are ...

11. First 10 digits of the sum of 100 50 digit numbers (Project Euler # 13)    coderanch.com

Ok, I stored the numbers in a String array and I'm trying to parse them one at a time and store them into a long variable. Is 50 digits too large for a long data type?? If so should I be using BigInteger or some other data type in java??? Here's what I have so far: Whenever I run this code, ...

12. sum up numbers    coderanch.com

Hi, in this program, supposed to add odd numbers it works when num1 <= numb2 : "10, 1" but when you enter num1 >=numb2 : "10,1" does not work and theres no errors what condition i have to add (when numb1>=numb2) and where i have to locate it. Thanks import java.util.Scanner; public class W06M2Prog5SumOddNums { public static void main(String args[]) { ...

13. Sum of all even numbers up to but not including 100    java-forums.org

First off- Hello everyone!! I am new to this forum and Java Programming. My Structure of Computer Programming instructor has been pretty redundant the first couple of lectures, and then out of no where gave us like 5 assignments, 2 of which are way beyond the scope of what we talked about in class. I did some research online and found ...

14. Sum of 4 numbers...!?    java-forums.org

Hi everyone I've a project to do,and i need some help.The project is "We have to add as input a double and than the input number must express as sum of four other numbers.It's analogy of monies.For example let's say we have 48.5 and we have to seperate this as sum of monies as 5,3,2,1 and cents".Hope that's clearly explained. Regards ...

15. Sum positive numbers using 10 inputs from user    java-forums.org

Hi I'm a little confused about this, I can't seem to get this to work corretly. What I'm trying to accomplish is I'm taking ten positive double number inputs and only printing out the positive ones plus the total. The problem is I don't know how to only have it except 10 inputs and also it's not totaling the inputs correctlly. ...

16. Math problem Sum of a hundred 50 digit numbers.    java-forums.org

I am trying to figure out this math problem. "Work out the first ten digits of the sum of the following one-hundred 50-digit numbers." Basically I copied the 50 digit numbers from the link about and pasted them into the IDE. I named it hugeString. 1) Do you think I was on the right track with idea 1 or 2 or ...





17. Digit sum of extremely large numbers    java-forums.org

18. program to sum digits in a number    forums.oracle.com

Personally, I prefer using java.util.CircularList. Initialise it to contain the nine non-zero digits, then just advance through the list the number of places specified by the given number. Moving 10 or 100, or 1000 etc places is identical in effect to moving 1 place, so the effet of each digit is independent of its place and you should end up in ...

19. Sum of numbers    forums.oracle.com

I don't get any errors, and when I type in 3, I get the correct answer of 6 (1+2+3 = 6) That was just luck. but when I type in 5, I get an answer of 10. This line: sum = ((number) + (number--)); which can be written without all the parentheses, like this: sum = number + number-- Says add ...

20. Sum of user entered number    forums.oracle.com

21. Problem : Sum & Adverage Of Ten Numbers ?    forums.oracle.com

1. Why are you calculating average each time around the loop? 2. Why are you calculating the average by dividing by the last number entered by user? 3. When you divide an int by an int the result will be an int not a double. eg 9 / 2 = 4 not 4.5

22. sum of two numbers    forums.oracle.com

Please try to write in normal English. 'u' should be 'you' and sentences start with a capital and end with a single punctuation mark. I'm not saying you should write in flawless English, but I get the impression you can do a hell of of lot better than this. That said, do you know what a constructor is?

23. sum one-hundred 50-digit numbers    forums.oracle.com

Work out the first ten digits of the sum of the following one-hundred 50-digit numbers. 37107287533902102798797998220837590246510135740250 46376937677490009712648124896970078050417018260538 74324986199524741059474233309513058123726617309629 91942213363574161572522430563301811072406154908250 23067588207539346171171980310421047513778063246676 89261670696623633820136378418383684178734361726757 28112879812849979408065481931592621691275889832738 44274228917432520321923589422876796487670272189318 47451445736001306439091167216856844588711603153276 70386486105843025439939619828917593665686757934951 62176457141856560629502157223196586755079324193331 64906352462741904929101432445813822663347944758178 92575867718337217661963751590579239728245598838407 58203565325359399008402633568948830189458628227828 80181199384826282014278194139940567587151170094390 35398664372827112653829987240784473053190104293586 86515506006295864861532075273371959191420517255829 71693888707715466499115593487603532921714970056938 54370070576826684624621495650076471787294438377604 53282654108756828443191190634694037855217779295145 36123272525000296071075082563815656710885258350721 45876576172410976447339110607218265236877223636045 17423706905851860660448207621209813287860733969412 81142660418086830619328460811191061556940512689692 51934325451728388641918047049293215058642563049483 62467221648435076201727918039944693004732956340691 15732444386908125794514089057706229429197107928209 55037687525678773091862540744969844508330393682126 18336384825330154686196124348767681297534375946515 80386287592878490201521685554828717201219257766954 78182833757993103614740356856449095527097864797581 16726320100436897842553539920931837441497806860984 48403098129077791799088218795327364475675590848030 87086987551392711854517078544161852424320693150332 59959406895756536782107074926966537676326235447210 69793950679652694742597709739166693763042633987085 41052684708299085211399427365734116182760315001271 65378607361501080857009149939512557028198746004375 35829035317434717326932123578154982629742552737307 94953759765105305946966067683156574377167401875275 88902802571733229619176668713819931811048770190271 25267680276078003013678680992525463401061632866526 36270218540497705585629946580636237993140746255962 24074486908231174977792365466257246923322810917141 91430288197103288597806669760892938638285025333403 34413065578016127815921815005561868836468420090470 ...

24. Generating all possible difference between the sum of 2 group of numbers    forums.oracle.com

Hello everyone, I'm faced with a problem relatively new to me and need a source code for solving it. The problem requires me to come out with all possible difference between the sum of 2 group of numbers. An example of 1 possible difference is as shown below e.g. 10 random numbers say {1,2,3,4,5,6,7,8,9,10} Group 1 = {1,2,3,4,5} Sum of Group ...

25. sum of prime numbers    forums.oracle.com

If you want to speed up the calculation, store all of the prime numbers you find in an array. Then for each new number you test for being a prime, you only need to divide by the numbers in the array. It saves a lot of time as you get to higher numbers. I recently did a prime number program that ...

26. sum of odd numbers code help    forums.oracle.com

calculates and returns the sum of all the odd numbers from 1 to x.? this is what i have so far: for (count = 1; i = x; i++) { sum = 0; count + 2; sum = count } i = i + 2 when i compile, i get an error because count + 2; is not a statement. why? ...

27. More prime number crunching. (sum of 2 suqares)    forums.oracle.com

I didn't try this algorithm, but may be give you some idea for reference. Let say you input the number n. Then find the square up to r where 1^2, 2^2 .... r^2 < n You have two index, a and b starting from a=1, b=r 1) a^2 + b^2 = n ? yes -> you got the answer no -> ...

28. Computing the sum and prime number help.    forums.oracle.com

the new one i've been trying to make hasn't worked like i planned so i've been messing with variables and whatnot so now it looks kinda messed up and well...its probably useless. i know what a prime number is, where it is only divisible by 1 and itself and i have been reading other material on here about primes but none ...