0% found this document useful (0 votes)
2 views3 pages

Operators in Java - V

The document presents various Java code snippets demonstrating the use of operators and type casting in Java. Each code example illustrates different scenarios involving data types such as byte, short, int, long, float, and double, along with their conversions and outputs. The content is part of a module from Abhishek Sir's Java classes.

Uploaded by

saksham.rkl2010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Operators in Java - V

The document presents various Java code snippets demonstrating the use of operators and type casting in Java. Each code example illustrates different scenarios involving data types such as byte, short, int, long, float, and double, along with their conversions and outputs. The content is part of a module from Abhishek Sir's Java classes.

Uploaded by

saksham.rkl2010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

ABHISHEK SIR'S JAVA CLASSES | OPERATORS IN JAVA

OPERATORS IN JAVA
MODULE - IV
I. Find the output:

a)
public class Ap
{
public static void main()
{
byte x;
int a = 70;
double b = 122.128;
x = (byte) a;
System.out.println("a and x " + a + " " + x);
a = (int) b;
System.out.println("b and a " + b + " " + a);
x = (byte)b;
System.out.println("b and x " + b + " " + x);
}
}

b)
class Ap
{
public static void main()
{
long l = 30;
int i = 50;
short s = 60;
byte b = 70;
double sum = l + i + s + b;
System.out.println("Sum = " + sum);
}
}

Abhishek Sir’s Java Classes © Copyright Reserved


1
ABHISHEK SIR'S JAVA CLASSES | OPERATORS IN JAVA

c)
class Ap
{
public static void main()
{
long l = 55;
int i = 44;
short s = 33;
byte b = 22;

i = (int) l;
s = (short) i;
b = (byte) s;

System.out.println("l = " + l);


System.out.println("i = " + i);
System.out.println("s = " + s);
System.out.println("b = " + b);
}
}

d)
class Ap
{
public static void main()
{
int i = 44;
float f = 98.42f;
double d = 103.67;

f = i;
d = f;
i = (int) d;

System.out.println("i = " + i);


System.out.println("f = " + f);
System.out.println("d = " + d);
}
}

Abhishek Sir’s Java Classes © Copyright Reserved


2
ABHISHEK SIR'S JAVA CLASSES | OPERATORS IN JAVA

e)
public class Ap {

public static void main() {


long l = 22;
long e = l + 3;
boolean m = l < e;
float o = 12.5f;
double n = o * 2;
System.out.println(l + "e" + m + "o" + n);
}
}

f)
public class Ap {
public static void main() {
int i = 122;
short s = 15;
byte b = (byte) i;
int x = b + s;
System.out.println("Value of x is " + x);
}
}

g)
class Ap
{
public static void main()
{
byte b = 42;
char c = 'a';
short s = 1024;
int i = 50000;
float f = 5.67f;
double d = .1234;
double result = (f * b) + (i / c) - (d * s);
System.out.println(result);
}
}

Abhishek Sir’s Java Classes © Copyright Reserved


3

You might also like