Assume a program has the following declarations short s 2 i


Assume a program has the following declarations short s = 2; int i = -3; long m = 5; float f = 6.9 f, double d = 7.8; What are the following values? f/1 s + m d + s

Solution

2.Given :-

short s = 2 ;
int i = -3 ;
long m = 5 ;
float f = 6.9f ;
double d = 7.8 ;

OUTPUT1 :-

If we place the given expressions in System.out.println then we get the values like below.

  

Explanation :-

System.out.println( f/i ) ;

System.out.println( s+m ) ;

System.out.println( d*s ) ;

OUTPUT2 :-

If we assign the given expressions to any variable and then If we place the variable in System.out.println then we may get the Compiletime Error :- Incompatible Types.

Explanation :-

int a,b,c ;

short s = 2 ;

int i = -3 ;
long m = 5 ;

float f = 6.9f ;
double d = 7.8 ;

a = f/i ;

b = s+m ;

c = d*s ;

System.out.println( a ) ;

System.out.println( b ) ;

System.out.println( c ) ;

Given Expression The value of Given Expression
f/i -2.3
s+m 7
d*s 15.6
 Assume a program has the following declarations short s = 2; int i = -3; long m = 5; float f = 6.9 f, double d = 7.8; What are the following values? f/1 s + m

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site