Pratian technologies
Company
Programming
Program
state the output of the following code:
intnum=8;
inti=1;
int s=-1;
while(i<=num)
System.out.println((i++*s=-s)) +" ");
Read Solution (Total 20)
-
- compile time error (lvalue required)
- 9 years agoHelpfull: Yes(13) No(0)
- Guys the correct question is:
int num=8;
int i=1;
int s=-1;
while(i - 9 years agoHelpfull: Yes(13) No(6)
Here the question itself is wrongly written, correct question
state the output of the following code:
int num = 8;
int i = 1;
int s = -1;
while(i- 9 years agoHelpfull: Yes(12) No(0)
- it shows compile time error at i++*s=-s.
Because it is an assignment statement .
in first iteration it will become (1*-1=1) ==> (-1=1) ----> In case of assignment we need a variable.but here a value is founded by the compiler.
If we assume that for comparison then == is needed then only it is correc t program. - 9 years agoHelpfull: Yes(7) No(0)
- 1,-2,3,-4,5,-6,7,-8
- 9 years agoHelpfull: Yes(5) No(1)
- its shows compile time error
- 9 years agoHelpfull: Yes(4) No(0)
- i++ * s =- s
2*-1=2
2,3,4,5,6,7,8 - 8 years agoHelpfull: Yes(3) No(1)
- it should be (i++*(s=-s))
op: 1 -2 3 -4 5 -6 7 -8 - 7 years agoHelpfull: Yes(3) No(1)
- In java whenever we assign value to the constant for eg. 7=7
Then it will show error "required variable ,found value" and same will happen here on line i++*s=-s - 7 years agoHelpfull: Yes(3) No(0)
- Either question is mistyped or possible error might be lvalue required.
- 9 years agoHelpfull: Yes(2) No(0)
- guys the question is like this...
intnum=8;
inti=1;
int s=-1;
while(i - 8 years agoHelpfull: Yes(2) No(2)
- i think it should be 1 1 1 1 1 1 1 1
- 9 years agoHelpfull: Yes(1) No(3)
- output :
1 -2 3 -4 ... . . .8 - 9 years agoHelpfull: Yes(1) No(1)
- correct the stmt as i++*(s=-s)
here we are assigning -s to s , so for 1st iteration s value will be1
2nd -1,
3rd 1
4th -1
5th 1
6th -1
7th 1
8th -1
and the answer is
1,-2,3,-4,5,-6,7,-8 - 7 years agoHelpfull: Yes(1) No(0)
- i think its 8
- 9 years agoHelpfull: Yes(0) No(1)
- 1 0 0 0 0 0 0 0
- 9 years agoHelpfull: Yes(0) No(1)
- guys change last statement as:
System.out.println((i++*(s=-s))+" "); - 8 years agoHelpfull: Yes(0) No(1)
- num=8;
i=1;
s=-1;
while(1 - 8 years agoHelpfull: Yes(0) No(2)
- In java whenever we assign value to the constant for eg. 7=7
Then it will show error "required variable ,found value" and same will happen here on line i++*s=-s - 7 years agoHelpfull: Yes(0) No(0)
- Its shows Syntax error on token "=",
- 7 years agoHelpfull: Yes(0) No(0)
Pratian technologies Other Question