Task - Java Language Fundamentals - Variables #78
akash-coded
started this conversation in
Tasks
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 |
0 replies
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: |
0 replies
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 |
0 replies
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));
}
} |
0 replies
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 |
0 replies
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 |
0 replies
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 |
0 replies
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));
}
} |
0 replies
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));
}
} |
0 replies
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));
}
} |
0 replies
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));
}
} |
0 replies
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: |
0 replies
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));
}
} |
0 replies
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 |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment












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:
aandbof 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 usingaandb:a + ba - ba * ba / ba % ba > ba < ba << ba >> bFor example, if
a = 2andb = 3, the result ofa + bshould be displayed as:All reactions