Why is the following statement legal in C but not in Java? [duplicate]
This question already has an answer here:
Ternary operator in java vs c [duplicate]
1 answer
Why is the following statement legal in C but not in Java?
int k = 1;
(10 < 20) ? k++ : k--;
java c ternary-operator
marked as duplicate by Sotirios Delimanolis
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 17:23
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Ternary operator in java vs c [duplicate]
1 answer
Why is the following statement legal in C but not in Java?
int k = 1;
(10 < 20) ? k++ : k--;
java c ternary-operator
marked as duplicate by Sotirios Delimanolis
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 17:23
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
15
Because Java is not C
– Hovercraft Full Of Eels
Nov 15 '18 at 3:54
2
Neither of the proposed dupes addresses the OP's question. The problem they address deals with using non-expression statements on the RHS. The OP's problem is caused by the absence of the LHS.
– DYZ
Nov 15 '18 at 4:02
@flakes: Make that an answer after this is reopened.
– R..
Nov 15 '18 at 4:27
add a comment |
This question already has an answer here:
Ternary operator in java vs c [duplicate]
1 answer
Why is the following statement legal in C but not in Java?
int k = 1;
(10 < 20) ? k++ : k--;
java c ternary-operator
This question already has an answer here:
Ternary operator in java vs c [duplicate]
1 answer
Why is the following statement legal in C but not in Java?
int k = 1;
(10 < 20) ? k++ : k--;
This question already has an answer here:
Ternary operator in java vs c [duplicate]
1 answer
java c ternary-operator
java c ternary-operator
edited Nov 15 '18 at 3:53
Hovercraft Full Of Eels
262k20212318
262k20212318
asked Nov 15 '18 at 3:52
Zabi KhanZabi Khan
132
132
marked as duplicate by Sotirios Delimanolis
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 17:23
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Sotirios Delimanolis
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 16 '18 at 17:23
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
15
Because Java is not C
– Hovercraft Full Of Eels
Nov 15 '18 at 3:54
2
Neither of the proposed dupes addresses the OP's question. The problem they address deals with using non-expression statements on the RHS. The OP's problem is caused by the absence of the LHS.
– DYZ
Nov 15 '18 at 4:02
@flakes: Make that an answer after this is reopened.
– R..
Nov 15 '18 at 4:27
add a comment |
15
Because Java is not C
– Hovercraft Full Of Eels
Nov 15 '18 at 3:54
2
Neither of the proposed dupes addresses the OP's question. The problem they address deals with using non-expression statements on the RHS. The OP's problem is caused by the absence of the LHS.
– DYZ
Nov 15 '18 at 4:02
@flakes: Make that an answer after this is reopened.
– R..
Nov 15 '18 at 4:27
15
15
Because Java is not C
– Hovercraft Full Of Eels
Nov 15 '18 at 3:54
Because Java is not C
– Hovercraft Full Of Eels
Nov 15 '18 at 3:54
2
2
Neither of the proposed dupes addresses the OP's question. The problem they address deals with using non-expression statements on the RHS. The OP's problem is caused by the absence of the LHS.
– DYZ
Nov 15 '18 at 4:02
Neither of the proposed dupes addresses the OP's question. The problem they address deals with using non-expression statements on the RHS. The OP's problem is caused by the absence of the LHS.
– DYZ
Nov 15 '18 at 4:02
@flakes: Make that an answer after this is reopened.
– R..
Nov 15 '18 at 4:27
@flakes: Make that an answer after this is reopened.
– R..
Nov 15 '18 at 4:27
add a comment |
1 Answer
1
active
oldest
votes
This is because in C all expressions can be made into expression-statements by adding a semicolon ;
.
In Java not all expressions can be made into expression statements. They must be assignment expressions, use postfix/prefix operators, be method invocations, or new expressions. See more here
Further, a ternary operator in Java requires that each operand be a non void expression and the value returned must be assigned.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is because in C all expressions can be made into expression-statements by adding a semicolon ;
.
In Java not all expressions can be made into expression statements. They must be assignment expressions, use postfix/prefix operators, be method invocations, or new expressions. See more here
Further, a ternary operator in Java requires that each operand be a non void expression and the value returned must be assigned.
add a comment |
This is because in C all expressions can be made into expression-statements by adding a semicolon ;
.
In Java not all expressions can be made into expression statements. They must be assignment expressions, use postfix/prefix operators, be method invocations, or new expressions. See more here
Further, a ternary operator in Java requires that each operand be a non void expression and the value returned must be assigned.
add a comment |
This is because in C all expressions can be made into expression-statements by adding a semicolon ;
.
In Java not all expressions can be made into expression statements. They must be assignment expressions, use postfix/prefix operators, be method invocations, or new expressions. See more here
Further, a ternary operator in Java requires that each operand be a non void expression and the value returned must be assigned.
This is because in C all expressions can be made into expression-statements by adding a semicolon ;
.
In Java not all expressions can be made into expression statements. They must be assignment expressions, use postfix/prefix operators, be method invocations, or new expressions. See more here
Further, a ternary operator in Java requires that each operand be a non void expression and the value returned must be assigned.
answered Nov 15 '18 at 4:28
flakesflakes
6,79812051
6,79812051
add a comment |
add a comment |
15
Because Java is not C
– Hovercraft Full Of Eels
Nov 15 '18 at 3:54
2
Neither of the proposed dupes addresses the OP's question. The problem they address deals with using non-expression statements on the RHS. The OP's problem is caused by the absence of the LHS.
– DYZ
Nov 15 '18 at 4:02
@flakes: Make that an answer after this is reopened.
– R..
Nov 15 '18 at 4:27