Java

swirly

Active Member
Messages
1,930
Reaction score
0
Points
36
I'm guessing this is the right place. I ned help with an assignment. I have to write a program in JAVA. I just need to know how to concantenate 3 integers.
Code:
class SumDigit
{   public static void main(String args[])
    {
        int proof=0;
        for(int a=1; a<=9; a++)
        {
            for(int b=0; b<=9; b++)
            {
                for(int c=0; c<=9; c++)
                {
                    int sum=a+b+c;
                    int square=sum*sum;
                    proof=square%square;
                }
            }
        }
        System.out.print(proof);
        
    }
}
proof=square%square;
should be proof=abc(concantenated)%square; Then it needs to check if the remainder is anything but 0.
 
Last edited:

dbojan

New Member
Messages
99
Reaction score
1
Points
0
Do you mean something like this:
int concatenated=a*100+b*10+c;
?
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
Code:
proof=(a*100+b*10+c)%square;
If I understand what you mean.
It's only that easy because you're working with numbers between 0 and 9. Otherwise you should use logarithmic stuff to determine the length of the numbers etc.
 

gkglock

New Member
Messages
4
Reaction score
0
Points
0
If your looking to concatenate integers it would probably be best to use the StringBuilder class. Then convert the string with the parseint methnod.
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
If your looking to concatenate integers it would probably be best to use the StringBuilder class. Then convert the string with the parseint methnod.

You could, but it's much more mathematical to do it with logarithms ;)
 
Top