Login
|
Signup
langref.org
-
java
,
cpp
,
csharp
, and
clojure
add..
all
erlang
fantom
fsharp
go
groovy
haskell
ocaml
perl
php
python
ruby
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Strings
Declaration
Define a string containing variables and expressions
Given variables a=3 and b=4 output
"3+4=7"
java
System.out.println(a + "+" + b + "=" + (a+b));
public class Solution52 {
public static void main(String[] args) {
int a = 3;
int b = 4;
System.out.println(a + "+" + b + "=" + (a+b));
}
}
java
1.5 or later
System.out.printf("%d+%d=%d\n", a, b, a + b);
public class Solution370 {
public static void main(String[] args) {
int a = 3, b = 4;
System.out.printf("%d+%d=%d\n", a, b, a + b);
}
}
cpp
C++/CLI .NET 2.0
Console::WriteLine(L"{0}+{1}={2}", a, b, a+b);
using namespace System;
int main()
{
int a = 3, b = 4;
Console::WriteLine(L"{0}+{1}={2}", a, b, a+b);
}
cpp
std::printf("%d+%d=%d\n", a, b, a+b);
#include <cstdio>
int main()
{
int a = 3, b = 4;
std::printf("%d+%d=%d\n", a, b, a+b);
}
cpp
std::cout << boost::format("%|1|+%|1|=%|1|") % a % b % (a+b) << std::endl;
#include "boost/format.hpp"
int main()
{
int a = 3, b = 4;
std::cout << boost::format("%|1|+%|1|=%|1|") % a % b % (a+b) << std::endl;
}
csharp
int a = 3;
int b = 4;
Console.WriteLine("{0}+{1}={2}", a,b,a+b);
class SolutionXX
{
static void Main()
{
int a = 3;
int b = 4;
Console.WriteLine("{0}+{1}={2}", a,b,a+b);
}
}
clojure
(format "%d + %d = %d" a b (+ a b))
(format "%d + %d = %d" a b (+ a b))
Submit a new solution for
java
,
cpp
,
csharp
, or
clojure
There are 23 other solutions in
additional
languages (
erlang
,
fantom
,
fsharp
,
go
...)