# sum « Integer « Java Data Type Q&A

### 1. check if two integers sum to a third    stackoverflow.com

Ok I'm doing this programming assignment and need a little help. Here is the problem: Given three ints, a b c, return true if it is possible to add two of the ints ...

### 2. Java: sum of two integers being printed as concatenation of the two    stackoverflow.com

class giri{
public static void main(String args[])
{
int x = 17;
int y = 013;
...

### 3. Better way of calculating sum of even ints    stackoverflow.com

I'm trying to write a programme to prompt the user to input an int which is above or equal 2. From this input the programme must then calculate and print the ...

### 4. sum of two random integers between 1 and 6    stackoverflow.com

public class SumOfTwoDice {
public static void main(String[] args) {
int SIDES = 6;
...

### 5. Summing integers    stackoverflow.com

the instructions are: Enter an integer (32 bit) and sum its digits, you may be given a negative or positive integer. When reading in a negative integer, sum the digits but ...

### 6. compute the sum of DIGITS in integer    coderanch.com

Here's another stumper for me, I have to write a method to compute the sum of the digits of na integer, I.e. public static int sumDigits(long n) sumDigits(234)returns2+3+4=9. A hint is to use % to extract and / to remove extracted digits. I have NO CLUE where to begin!!! ANY help would be much appreciated!!!

### 7. Sum the digits of an integer.    coderanch.com

I have already gotten one good response to this one, but now I can't understand how to extract the digits so I can sum them together (2 + 3 + 4 =9). Anyone got any great idea? Here's the code I already got: public class Test{ public static void main(String[] args){ int i = 234; sumDigits(i);} private static void sumDigits(int digits){System.out.println("digits ...

### 11. How can I get the sum of a method that returns an int in a loop    forums.oracle.com

Hello peps, I have two method: 1. hasMoreItems() that returns a Boolean value and 2. getNumberOfErrors() that returns a int. If my Jsp code, I have a while Loop that checks the number of Documents as in <%while( document.hasMoreItems() ) {% and then within the loop it returns the number of errors for each individual document by using the second method ...

### 12. how to get the total sum of 3 integer?    forums.oracle.com

Dear All I wanted to get the sum of three integer but I ended up getting a different ans. please help. public class NumPlusNum { public static void main(String[]arg) { int x = 2; int y = 4; int z = 6; System.out.println("The sum total is :" + x + y + z); } } when I compile and run, it ...

### 13. Integer as sum of 2 squares.........    forums.oracle.com

Hi All, Only using "for" loops how can we calculate the number of ways an integer can be expressed as sum of 2 integers. example: On input 5, return 1 since 5 = 1*1 + 2*2 is the only solution. On input 65, return 2 since 65 = 1*1 + 8*8 = 4*4 + 7*7 Gita.

### 14. consequtive sequence of positive integers = target sum, must build algoryth    forums.oracle.com

I need to build an algorythm that will when given a target sum such as I x = 1986, the subrange sums are {160 ... 171}, {495 ... 498}, and {661 ... 663}. I think I can code it if I can figure out the math,algo-meth etc...Anyone got a lifetime to spend???? There is a formula i found for determining the ...

### 15. Sum of positve integers    forums.oracle.com

@ the OP I made a mistake when I started programming. I tried to do too much in 1 method or class. Get some input Test it for validness IF valid then call a method as needed to do what you want In that method you called You can Increment a variable each time it is called Accept a parameter that ...

### 16. sum and average of a list of integers    forums.oracle.com

Confirming code correctness 101 1.) Get paper. 2.) Get a pen. 3.) Calculate whatever your application is supposed to calculate using the pen and paper. 4.) Execute your application using the values used in step 3. 5.) Compare your final answer to that of your application. 6.) If the answers match, chances are that your code is correct.

### 17. Calculate sum of long integer!    forums.oracle.com

Im new to java and just started to learn but have a little problem. What I want to know is how I can get a long integer from the user and then caculate the sum of the separate numbers? I thinking I would use som sort of array and then calculate from there. The thing is Im use to ada programminglanguage ...

### 18. sum, add integers    forums.oracle.com

The trouble is that total is defined as a local variable inside the for loop. Every time you enter the loop, you parse another string to be a number, define total to be zero, add zero and the latest number together and assign it to total, then print total -- no wonder that just prints out the number. Define total outside ...

### 19. sum and average of ints    forums.oracle.com

double average = total/count; System.out.println(average); } } By the way, there are two plusses after 'count' in the while loop, but I couldn't get them here... However, now I get the error messages that the variables s, total and count might not have been initialized. Could anyone help me out of this? I've initialized total and count, but how do you ...

### 20. Program not work quite right (sum integers evens and odds?)    forums.oracle.com

So im trying to have the program read a set of integers and then print the sum of the even and odd integers. Only when I run what I have it finds the sum of all the even intergers and odd integers based on the number < than the input. I wanna be able to type in 10, 12, 15 and ...

### 21. Sum of digits in an integer    forums.oracle.com

/** *Write a program that calculates and displays the "sum of digits" *of a positive, non-zero integer entered by the user. * *The sum of digits is the sum of each digit in that integer, reduced *to a value in the range 1-9 by repeating the sum of digits calculation *whenever a sum of digits is greater than 9. For example, ...