System.out.print() is used to print on output devices in java programs.
To print a text with a number we use
int a = 5;
System.out.print("a = "+ a);
It prints a=5
We can also add two numbers in System.out.print()
int a=5, b=9;
System.out.print(a+b);
It will print 14
If the first two value passed to System.out.print() is number than it treats + as addition operator otherwise as concatenation operator.
e.g
int a=1, b=2;
System.out.print(a+b);
System.out.print(a+b+" is the sum");
System.out.print("Sum is"+a+b);
Output will be
3
3 is the sum
Sum is 12 // Instead of adding a and b + concatenates them.
To print a text with a number we use
int a = 5;
System.out.print("a = "+ a);
It prints a=5
We can also add two numbers in System.out.print()
int a=5, b=9;
System.out.print(a+b);
It will print 14
If the first two value passed to System.out.print() is number than it treats + as addition operator otherwise as concatenation operator.
e.g
int a=1, b=2;
System.out.print(a+b);
System.out.print(a+b+" is the sum");
System.out.print("Sum is"+a+b);
Output will be
3
3 is the sum
Sum is 12 // Instead of adding a and b + concatenates them.
No comments:
Post a Comment