View Problem

Define a string containing variables and expressions

Given variables a=3 and b=4 output "3+4=7"
ExpandDiskEdit
ruby
puts "#{a}+#{b}=#{a+b}"
ExpandDiskEdit
ruby
puts "#{a}+#{b}=%s" % (a + b)
ExpandDiskEdit
java
System.out.println(a + "+" + b + "=" + (a+b));
ExpandDiskEdit
java 1.5 or later
System.out.printf("%d+%d=%d\n", a, b, a + b);
ExpandDiskEdit
perl
print "$a+$b=${\($a+$b)}\n";
DiskEdit
perl
sprintf("%d+%d=%d", $a, $b, $a + $b);
DiskEdit
perl
print $a, '+', $b, '=', $a + $b;
ExpandDiskEdit
groovy
println "$a+$b=${a+b}"
ExpandDiskEdit
groovy
printf "%d+%d=%d\n", a, b, a + b
ExpandDiskEdit
scala Java 1.5 or later
printf("%d+%d=%d\n", a, b, a + b)
DiskEdit
scala
"%d+%d=%d".format(a, b, a + b)
DiskEdit
scala 2.10
s"$a + $b = ${a+b}"
DiskEdit
python
class EvalDict(dict):
def __getitem__(s, k):
return eval(k, s)

a=3; b=4
"%(a)d+%(b)d=%(a+b)d" % EvalDict(locals())
DiskEdit
python
a=3; b=4
"%d+%d=%d" % (a, b, a+b)
ExpandDiskEdit
cpp C++/CLI .NET 2.0
Console::WriteLine(L"{0}+{1}={2}", a, b, a+b);
ExpandDiskEdit
cpp
std::printf("%d+%d=%d\n", a, b, a+b);
ExpandDiskEdit
cpp
std::cout << boost::format("%|1|+%|1|=%|1|") % a % b % (a+b) << std::endl;
ExpandDiskEdit
fsharp
let a, b = 3, 4
let mystr = sprintf "%d+%d=%d" a b (a+b)
printfn "%s" mystr
ExpandDiskEdit
erlang
A = 3, B = 4,
io:format("~B+~B=~B~n", [A, B, (A+B)]).
DiskEdit
ocaml
Printf.printf "%d+%d=%d" a b (a+b);;
DiskEdit
ocaml
Printf.printf "%d+%d=%d" a b (a+b);;
ExpandDiskEdit
csharp
int a = 3;
int b = 4;
Console.WriteLine("{0}+{1}={2}", a,b,a+b);
ExpandDiskEdit
php
echo "$a+$b=".($a+$b);
ExpandDiskEdit
php
printf("%d+%d=%d\n", $a, $b, $a + $b);
DiskEdit
haskell
import Text.Printf

main = do
let a = 3
let b = 4
printf "%d+%d=%d" a b (a + b)
DiskEdit
haskell
a = 3
b = 4
s = show a ++ "+" ++ show b ++ "=" ++ show (a + b)
main = putStrLn s
DiskEdit
clojure
(format "%d + %d = %d" a b (+ a b))
ExpandDiskEdit
fantom
echo("$a+$b=${a+b}")
ExpandDiskEdit
go
a, b := 3, 4
fmt.Printf("%d+%d=%d\n", a, b, a + b)
ExpandDiskEdit
go
a, b := 3, 4
fmt.Println(a, "+", b, "=", a+b)

Submit a new solution for ruby, java, perl, groovy ...