Donate SIGN UP

F . A . O. T. T. T.

Avatar Image
kuiperbelt | 12:48 Fri 07th Jul 2023 | Science
12 Answers
Computer program or computer code required to verify answers 1998 and 2016 to previous birthday question!!

Gravatar

Answers

1 to 12 of 12rss feed

Avatar Image
Here's a shorter Fortran version: program age do i = 2025,1925,-1 n = i k = 0 do if(n == 0) exit j = mod(n,10) k = k + j n = n / 10 end do if(k == 2025 - i) print "(2i4)", i, k end do end program age It can be run here: https://www.tutorialspoint.com/compile_fortran_online.php
08:59 Sat 08th Jul 2023
Here's a Java version:
public class age{
public int sumDigits(int x)
{
String s = String.valueOf(x);
int sum = 0;
for(int i = 0; i1925; i--)
{
int age = 2025 - i;
int tot = sumDigits(i);
if(age == tot) System.out.println(String.valueOf(i)+" "+String.valueOf(age));
}
}
public static void main(String[] args){
new age();
}
}

If AB doesn't mess it up, it can be run here:
https://www.programiz.com/java-programming/online-compiler/
yeah I did mine in Rexx much shorter!
AB has indeed messed it up, specifically removing the "less than" symbol on the line beginning "for(int". It interprets < and > as HTML and strips them out.
The problem is that you cannot reliably put code out in AB , that's why I did psuedo code. Anyway you gave my BA to that idiot Zebu.
I see I can't even fix it using >
That's correct, because the div elements are populated using innerText rather than innerHtml.
Here's another attempt:
public class age{
public int sumDigits(int x)
{
String s = String.valueOf(x);
int sum = 0;
int i =0;
while(i != s.length()){
sum += Integer.parseInt(String.valueOf(s.charAt(i)));
i++;
}
return sum;
}
age(){
int i = 2025;
while(i != 1925){
int age = 2025 - i;
int tot = sumDigits(i);
if(age == tot) System.out.println(String.valueOf(i)+" "+String.valueOf(age));
i--;
}
}
public static void main(String[] args){
new age();
}
}

https://www.programiz.com/java-programming/online-compiler/
Here's a shorter Fortran version:

program age
do i = 2025,1925,-1
n = i
k = 0
do
if(n == 0) exit
j = mod(n,10)
k = k + j
n = n / 10
end do
if(k == 2025 - i) print "(2i4)", i, k
end do
end program age

It can be run here:
https://www.tutorialspoint.com/compile_fortran_online.php
Ok here's a COBOL version the actual code, and the answers it generates:
https://ibb.co/kBJthDB
Question Author
Radagast, sadly your Java versions will not compute. My neighbour verifies the Fortran program and so BA goes to you, narrowly beating TTT whose program just falls short of presenting the age/s.
I've just copied and pasted my second java version into the given link and it works. Post at 15:44 Fri.
"TTT whose program just falls short of presenting the age/s. " - how? it presented the 2 answers perfectly?

1 to 12 of 12rss feed

Do you know the answer?

F . A . O. T. T. T.

Answer Question >>