Task - Java Language Fundamentals - Variables #78
Replies: 14 comments
-
String.formatpublic class Format {
public static void main(String[] args) {
int a=10;
int b=5;
System.out.println(String.format("The result of a+b is %d", a+b));
System.out.println(String.format("The result of a-b is %d", a-b));
System.out.println(String.format("The result of a*b is %d", a*b));
System.out.println(String.format("The result of a/b is %d", a/b));
System.out.println(String.format("The result of a modulo b is %d", a%b));
System.out.println(String.format("The result of a>b is %b", a>b));
System.out.println(String.format("The result of a<b is %b", a<b));
System.out.println(String.format("The result of a<<b is %d", a<<b));
System.out.println(String.format("The result of a>>b is %d", a>>b));
}
} output |
Beta Was this translation helpful? Give feedback.
-
String Formatclass StrFormat{
public static void main(String[] args){
int a=10, b=5;
System.out.println(String.format("Addition of a and b : %d", a+b));
System.out.println(String.format("Subtraction of a and b : %d", a-b));
System.out.println(String.format("Multiplication of a and b : %d", a*b));
System.out.println(String.format("Division of a and b : %d", a/b));
System.out.println(String.format("Modulus of a and b : %d", a%b));
System.out.println(String.format("a is greater than b : %B", a>b));
System.out.println(String.format("b is greater than a : %B", b>a));
System.out.println(String.format("Left Shift of a and b : %d", a<<b));
System.out.println(String.format("Right Shift of a and b : %d", a>>b));
}
} Output: |
Beta Was this translation helpful? Give feedback.
-
StringFormatterpublic class StringFormatDemo {
public static void main(String[] args) {
int a=11,b=22;
System.out.println(String.format("a=%d,b=%d",a,b));
System.out.println();
System.out.println(String.format("The result of a+b is %d", a+b));
System.out.println(String.format("The result of a-b is %d", a-b));
System.out.println(String.format("The result of a*b is %d", a*b));
System.out.println(String.format("The result of a/b is %d", a/b));
System.out.println(String.format("The result of mod a and b is %d", a%b));
System.out.println(String.format("The result of a>b is %s", a>b));
System.out.println(String.format("The result of a<b is %s", a<b));
System.out.println(String.format("The result of a>>b is %d", a>>b));
System.out.println(String.format("The result of a<<b is %d", a<<b));
}
} Output |
Beta Was this translation helpful? Give feedback.
-
Fundamentalspublic class Sample {
public static void main(String[] args) {
int a,b;
a=100;
b=50;
System.out.println(String.format("The result of a+b is %d",a+b));
System.out.println(String.format("The result of a-b is %d",a-b));
System.out.println(String.format("The result of a*b is %d",a*b));
System.out.println(String.format("The result of a/b is %d",a/b));
System.out.println(String.format("The result of a modulus b is %d",a%b));
System.out.println(String.format("The result of a>b is %B",a>b));
System.out.println(String.format("The result of a<b is %B",a<b));
System.out.println(String.format("The result of a<<b is %d",a<<b));
System.out.println(String.format("The result of a>b is %d",a>>b));
}
} |
Beta Was this translation helpful? Give feedback.
-
Calc.javaclass calc{
public static void main(String args[])
{
int a=4;
int b=2;
System.out.println(String.format("The result of a+b is %d",(a+b)));
System.out.println(String.format("The result of a-b is %d",(a-b)));
System.out.println(String.format("The result of a*b is %d",(a*b)));
System.out.println(String.format("The result of a/b is %d",(a/b)));
System.out.println(String.format("The result of a modulous b is %d",(a%b)));
System.out.println(String.format("The result of a>b is %b",(a>b)));
System.out.println(String.format("The result of a<b is %b",(a<b)));
System.out.println(String.format("The result of a<<b is %d",(a<<b)));
System.out.println(String.format("The result of a>>b is %d",(a>>b)));
}
} Output |
Beta Was this translation helpful? Give feedback.
-
TASK ON VARIABLESOutputFormatDemo.javapublic class OutputFormatDemo
{
public static void main(String[] args)
{
int a=10,b=5;
System.out.println(String.format("sum of a and b = %d", a+b));
System.out.println(String.format("subtraction of a and b = %d", a-b));
System.out.println(String.format("multiplication of a and b = %d", a*b));
System.out.println(String.format("division of a and b = %d", a/b));
System.out.println(String.format("modulus of a and b = %d", a%b));
System.out.println(String.format("a is greater than b = %s", a>b));
System.out.println(String.format("a is greater than b = %s", a<b));
System.out.println(String.format("values of a<<b = %d", a<<b));
System.out.println(String.format("values of a>>b = %d", a>>b));
}
} Output |
Beta Was this translation helpful? Give feedback.
-
String formatpublic class StrFormat {
public static void main(String[] args) {
int a = 10;
int b = 8;
System.out.println(String.format("a = %d, b = %d", a, b));
System.out.println(String.format("The result of a + b is is %d", (a + b)));
System.out.println(String.format("The result of a - b is is %d", (a - b)));
System.out.println(String.format("The result of a * b is is %d", (a * b)));
System.out.println(String.format("The division of a and b is is %d", (a / b)));
System.out.println(String.format("The modulus of a and b is %d", a % b));
System.out.println(String.format("The result of a > b is is %s", (a > b)));
System.out.println(String.format("The result of a < b is is %s", (a < b)));
System.out.println(String.format("The result of a << b is is %d", (a << b)));
System.out.println(String.format("The result of a >> b is is %d", (a >> b)));
}
} Output |
Beta Was this translation helpful? Give feedback.
-
Fundamentalspublic class VarEx {
public static void main(String[] args) {
int a=5;
int b=4;
System.out.println(String.format("The result of %d + %d = %d ",a,b,a+b));
System.out.println(String.format("The result of %d - %d = %d ",a,b,a-b));
System.out.println(String.format("The result of %d * %d = %d ",a,b,a*b));
System.out.println(String.format("The result of %d / %d = %d ",a,b,a/b));
System.out.printf("The result of %d Mod %d = %d %n ",a,b,a%b);
System.out.println(String.format("The result of %d < %d = %b ",a,b,a<b));
System.out.println(String.format("The result of %d > %d = %b ",a,b,a>b));
System.out.println(String.format("The result of %d << %d = %d ",a,b,a<<b));
System.out.println(String.format("The result of %d >> %d = %d ",a,b,a>>b));
}
} |
Beta Was this translation helpful? Give feedback.
-
public class AritOper {
public static void main(String[] args) {
int a=20;
int b=10;
System.out.println(String.format("The result of a+b is %d",a+b));
System.out.println(String.format("The result of a-b is %d",a-b));
System.out.println(String.format("The result of a*b is %d",a*b));
System.out.println(String.format("The result of a/b is %d",a/b));
System.out.printf("The result of a mod b is %d\n",a%b );
System.out.println(String.format("The result of a>b is %b",a>b));
System.out.println(String.format("The result of a<b is %b",a<b));
System.out.println(String.format("The result of a<<b is %d",a<<b));
System.out.println(String.format("The result of a>>b is %d",a>>b));
}
} |
Beta Was this translation helpful? Give feedback.
-
String Formatpublic class MainClass {
public static void main(String[] args) {
int a = 5;
int b=10;
System.out.println(String.format("The result of a + b is :: %d", a + b));
System.out.println(String.format("The result of a - b is :: %d", a - b));
System.out.println(String.format("The result of a * b is :: %d", a * b));
System.out.println(String.format("The result of a / b is :: %d", a / b));
System.out.println(String.format("The result of a modulo b is :: %d", a % b));
System.out.println(String.format("The result of a > b is :: %b", a > b));
System.out.println(String.format("The result of a < b is :: %b", a < b));
System.out.println(String.format("The result of a >> b is :: %d", a >> b));
System.out.println(String.format("The result of a << b is :: %d", a << b));
}
} |
Beta Was this translation helpful? Give feedback.
-
String Format Examplepublic class StringFormatExample {
public static void main(String[] args) {
int a = 27;
int b = 20;
System.out.println(String.format("The result a+b is :: %d",a+b));
System.out.println(String.format("The result a-b is:: %d",a-b));
System.out.println(String.format("The result a*b is:: %d",a*b));
System.out.println(String.format("The result a/b is:: %d",a/b));
System.out.println(String.format("The result a mod b is:: %d",a%b));
System.out.println(String.format("The result a>b is:: %b",a>b));
System.out.println(String.format("The result a<b is:: %b",a<b));
System.out.println(String.format("The result a>>b is:: %d",a>>b));
System.out.println(String.format("The result a<<b is:: %d",a<<b));
}
} |
Beta Was this translation helpful? Give feedback.
-
Sample.javapublic class Sample {
public static void main(String[] args){
int a=10;
int b=20;
System.out.println(String.format("The Result of a+b is: %d", a+b));
System.out.println(String.format("The Result of a-b is: %d", a-b));
System.out.println(String.format("The Result of a*b is: %d", a*b));
System.out.println(String.format("The Result of a/b is: %d", a/b));
System.out.println(String.format("The Result of a>b is: %b", a>b));
System.out.println(String.format("The Result of a<b is: %b", a<b));
System.out.println(String.format("The Result of a>>b is: %b", a>>b));
System.out.println(String.format("The Result of a<<b is: %b", a<<b));
System.out.println(String.format("The Result of a %% b is: %d", a%b));
}
} Output: |
Beta Was this translation helpful? Give feedback.
-
Variables using StringFormatpublic class Variables {
public static void main(String[] args) {
int a= 5 , b=10;
System.out.println(String.format("The result of a+b is %d",a+b));
System.out.println(String.format("The result of a - b is %d",a-b));
System.out.println(String.format("The result of a * b is %d",a*b));
System.out.println(String.format("The result of a / b is %d",a/b));
System.out.println(String.format("The result of a mod b is:%d",a%b));
System.out.println(String.format("The result of a > b is %s:",a>b));
System.out.println(String.format("The result of a < b is:%s",a<b));
System.out.println(String.format("The result of a << b is%d:",a<<b));
System.out.println(String.format("The result of a >> b is%d:",a>>b));
}
} |
Beta Was this translation helpful? Give feedback.
-
Variablespublic class Variable {
public static void main(String[] args) {
int a = 10;
int b = 20;
System.out.println(String.format("The result of a + b is %d ", a+b));
System.out.println(String.format("The result of a - b is %d ", a-b));
System.out.println(String.format("The result of a * b is %d ", a*b));
System.out.println(String.format("The result of a / b is %d ", a/b));
System.out.println(String.format("The result of a mod b is %d ", a%b));
System.out.println(String.format("The result of a > b is %b ", a>b));
System.out.println(String.format("The result of a < b is %b ", a<b));
System.out.println(String.format("The result of a >> b is %d ", a>>b));
System.out.println(String.format("The result of a << b is %d ", a<<b));
}
} Output |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Write a Java program where you are declaring two numbers:
a
andb
of typeint
.Assign values of your choice to the declared variables.
Then using
String.format()
, display the results, along with a message, of the following operations usinga
andb
:a + b
a - b
a * b
a / b
a % b
a > b
a < b
a << b
a >> b
For example, if
a = 2
andb = 3
, the result ofa + b
should be displayed as:Beta Was this translation helpful? Give feedback.
All reactions