Why can't I write ch=ch+1; instead of ch++; though they have same meaning
up vote
5
down vote
favorite
package practicejava;
public class Query {
public static void main(String args) {
char ch = 66;
System.out.println("character= " + ch);
ch++;
System.out.println("character = " + ch);
}
}
Technically ch++;
and ch=ch+1;
are the same but why do I get an error when I write ch=ch+1;
instead of ch++;
?
java int character increment
New contributor
add a comment |
up vote
5
down vote
favorite
package practicejava;
public class Query {
public static void main(String args) {
char ch = 66;
System.out.println("character= " + ch);
ch++;
System.out.println("character = " + ch);
}
}
Technically ch++;
and ch=ch+1;
are the same but why do I get an error when I write ch=ch+1;
instead of ch++;
?
java int character increment
New contributor
Welcome to Stack Overflow! Please have a look around, and read through the help center, in particular How do I ask a good question? "but why is here occur error" Always quote the exact error, rather than just saying you get an error. In this case, we can probably guess what error you're talking about, but you don't want to make the people trying to help you guess.
– T.J. Crowder
4 hours ago
It’s a confusing behaviour that has been taken over from C++ and its forerunners.
– Ole V.V.
4 hours ago
2
anint
plus achar
is anint
– Peter Lawrey
3 hours ago
Note that Java is one of the few languages that actually retains a distinct character type from C, in most languages characters are actually strings and won't compile (or will throw a runtime error) if you try to treat them as integers.
– Jared Smith
2 hours ago
@Tushar Mia : What should I do when someone answers my question?
– Nicholas K
38 mins ago
add a comment |
up vote
5
down vote
favorite
up vote
5
down vote
favorite
package practicejava;
public class Query {
public static void main(String args) {
char ch = 66;
System.out.println("character= " + ch);
ch++;
System.out.println("character = " + ch);
}
}
Technically ch++;
and ch=ch+1;
are the same but why do I get an error when I write ch=ch+1;
instead of ch++;
?
java int character increment
New contributor
package practicejava;
public class Query {
public static void main(String args) {
char ch = 66;
System.out.println("character= " + ch);
ch++;
System.out.println("character = " + ch);
}
}
Technically ch++;
and ch=ch+1;
are the same but why do I get an error when I write ch=ch+1;
instead of ch++;
?
java int character increment
java int character increment
New contributor
New contributor
edited 2 hours ago
孙兴斌
15.8k41644
15.8k41644
New contributor
asked 4 hours ago
Tushar Mia
323
323
New contributor
New contributor
Welcome to Stack Overflow! Please have a look around, and read through the help center, in particular How do I ask a good question? "but why is here occur error" Always quote the exact error, rather than just saying you get an error. In this case, we can probably guess what error you're talking about, but you don't want to make the people trying to help you guess.
– T.J. Crowder
4 hours ago
It’s a confusing behaviour that has been taken over from C++ and its forerunners.
– Ole V.V.
4 hours ago
2
anint
plus achar
is anint
– Peter Lawrey
3 hours ago
Note that Java is one of the few languages that actually retains a distinct character type from C, in most languages characters are actually strings and won't compile (or will throw a runtime error) if you try to treat them as integers.
– Jared Smith
2 hours ago
@Tushar Mia : What should I do when someone answers my question?
– Nicholas K
38 mins ago
add a comment |
Welcome to Stack Overflow! Please have a look around, and read through the help center, in particular How do I ask a good question? "but why is here occur error" Always quote the exact error, rather than just saying you get an error. In this case, we can probably guess what error you're talking about, but you don't want to make the people trying to help you guess.
– T.J. Crowder
4 hours ago
It’s a confusing behaviour that has been taken over from C++ and its forerunners.
– Ole V.V.
4 hours ago
2
anint
plus achar
is anint
– Peter Lawrey
3 hours ago
Note that Java is one of the few languages that actually retains a distinct character type from C, in most languages characters are actually strings and won't compile (or will throw a runtime error) if you try to treat them as integers.
– Jared Smith
2 hours ago
@Tushar Mia : What should I do when someone answers my question?
– Nicholas K
38 mins ago
Welcome to Stack Overflow! Please have a look around, and read through the help center, in particular How do I ask a good question? "but why is here occur error" Always quote the exact error, rather than just saying you get an error. In this case, we can probably guess what error you're talking about, but you don't want to make the people trying to help you guess.
– T.J. Crowder
4 hours ago
Welcome to Stack Overflow! Please have a look around, and read through the help center, in particular How do I ask a good question? "but why is here occur error" Always quote the exact error, rather than just saying you get an error. In this case, we can probably guess what error you're talking about, but you don't want to make the people trying to help you guess.
– T.J. Crowder
4 hours ago
It’s a confusing behaviour that has been taken over from C++ and its forerunners.
– Ole V.V.
4 hours ago
It’s a confusing behaviour that has been taken over from C++ and its forerunners.
– Ole V.V.
4 hours ago
2
2
an
int
plus a char
is an int
– Peter Lawrey
3 hours ago
an
int
plus a char
is an int
– Peter Lawrey
3 hours ago
Note that Java is one of the few languages that actually retains a distinct character type from C, in most languages characters are actually strings and won't compile (or will throw a runtime error) if you try to treat them as integers.
– Jared Smith
2 hours ago
Note that Java is one of the few languages that actually retains a distinct character type from C, in most languages characters are actually strings and won't compile (or will throw a runtime error) if you try to treat them as integers.
– Jared Smith
2 hours ago
@Tushar Mia : What should I do when someone answers my question?
– Nicholas K
38 mins ago
@Tushar Mia : What should I do when someone answers my question?
– Nicholas K
38 mins ago
add a comment |
3 Answers
3
active
oldest
votes
up vote
5
down vote
You need to provide a cast in order to do that :
ch = (char) (ch + 1);
This is because the expression ch + 1
is is promoted (upcast) to an int
. In order for you to reassign this expression to a char
you need to explicitly downcast it.
add a comment |
up vote
4
down vote
By ch+1
, the char ch
will be promoted to int
first, just like ((int)ch) + 1
, so the result will be an int
.
When you try assign an int
(32 bit) back to a char
(16 bit), it might loss accuracy, you need to do it explictly ch = (char)(ch + 1);
This is called Binary Numeric Promotion:
Binary numeric promotion is performed on the operands of certain
operators:
...
The addition and subtraction operators for numeric types + and - (§15.18.2)
and it will perform
Widening primitive conversion (§5.1.2) is applied to convert either or
both operands as specified by the following rules:
If either operand is of type double, the other is converted to double.
Otherwise, if either operand is of type float, the other is converted
to float.
Otherwise, if either operand is of type long, the other is converted
to long.
Otherwise, both operands are converted to type int.
add a comment |
up vote
2
down vote
First of all, note that a char
is 2 bytes large (16 bit), and an int
is 32bit.
1. When typing ch++
:
to apply the ++
operator, there is no type cast but the operator simply causes the bit represent of that char
to increase by 1 to itself. Refer to JLS11 chapter 15.14.2,page 575:
The type of the postfix increment expression is the type of the variable.
2. When typing ch=ch+1
:
ch
is firstly casted to int
, then it is added by 1
(still an int), and the =
is actually tring to cast the int
which has 32bits into a char
which has only 16
bits, note that this may lose accuracy. So without an explicitly cast, the compiler will complain about that, which is the cause of the error.
I did not understand the no. 1 point .if ch is casted into int when printing the value of ch after ch++; operation why it shows character instead of int.. Can You plz explain the first term details
– Tushar Mia
1 hour ago
1
[sorry for my bad English ] I mean : suppose at first I assign 'A' into ch .after I do the ch++; operation. here if ch would cast into int and then add value 1 . here corresponding Unicode value of A which is 65 then add 1 .total 66 so after when I perform the action System.out.print("character "+ch); it should show the output like this : character 66 . that all I understood from your second comment . the I asked you that why the output is character B if ch is casted into int then add int value 1
– Tushar Mia
30 mins ago
Thanks for pointing it out. Updated my post @Tushar Mia
– ZhaoGang
29 mins ago
what does it mean by ''the bit represent of that char"
– Tushar Mia
19 mins ago
By saying that I mean the value of that char, and that value is stored in the memory by a set of bits(16 bits)
– ZhaoGang
2 mins ago
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Tushar Mia is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53791297%2fwhy-cant-i-write-ch-ch1-instead-of-ch-though-they-have-same-meaning%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
You need to provide a cast in order to do that :
ch = (char) (ch + 1);
This is because the expression ch + 1
is is promoted (upcast) to an int
. In order for you to reassign this expression to a char
you need to explicitly downcast it.
add a comment |
up vote
5
down vote
You need to provide a cast in order to do that :
ch = (char) (ch + 1);
This is because the expression ch + 1
is is promoted (upcast) to an int
. In order for you to reassign this expression to a char
you need to explicitly downcast it.
add a comment |
up vote
5
down vote
up vote
5
down vote
You need to provide a cast in order to do that :
ch = (char) (ch + 1);
This is because the expression ch + 1
is is promoted (upcast) to an int
. In order for you to reassign this expression to a char
you need to explicitly downcast it.
You need to provide a cast in order to do that :
ch = (char) (ch + 1);
This is because the expression ch + 1
is is promoted (upcast) to an int
. In order for you to reassign this expression to a char
you need to explicitly downcast it.
answered 4 hours ago
Nicholas K
4,94141031
4,94141031
add a comment |
add a comment |
up vote
4
down vote
By ch+1
, the char ch
will be promoted to int
first, just like ((int)ch) + 1
, so the result will be an int
.
When you try assign an int
(32 bit) back to a char
(16 bit), it might loss accuracy, you need to do it explictly ch = (char)(ch + 1);
This is called Binary Numeric Promotion:
Binary numeric promotion is performed on the operands of certain
operators:
...
The addition and subtraction operators for numeric types + and - (§15.18.2)
and it will perform
Widening primitive conversion (§5.1.2) is applied to convert either or
both operands as specified by the following rules:
If either operand is of type double, the other is converted to double.
Otherwise, if either operand is of type float, the other is converted
to float.
Otherwise, if either operand is of type long, the other is converted
to long.
Otherwise, both operands are converted to type int.
add a comment |
up vote
4
down vote
By ch+1
, the char ch
will be promoted to int
first, just like ((int)ch) + 1
, so the result will be an int
.
When you try assign an int
(32 bit) back to a char
(16 bit), it might loss accuracy, you need to do it explictly ch = (char)(ch + 1);
This is called Binary Numeric Promotion:
Binary numeric promotion is performed on the operands of certain
operators:
...
The addition and subtraction operators for numeric types + and - (§15.18.2)
and it will perform
Widening primitive conversion (§5.1.2) is applied to convert either or
both operands as specified by the following rules:
If either operand is of type double, the other is converted to double.
Otherwise, if either operand is of type float, the other is converted
to float.
Otherwise, if either operand is of type long, the other is converted
to long.
Otherwise, both operands are converted to type int.
add a comment |
up vote
4
down vote
up vote
4
down vote
By ch+1
, the char ch
will be promoted to int
first, just like ((int)ch) + 1
, so the result will be an int
.
When you try assign an int
(32 bit) back to a char
(16 bit), it might loss accuracy, you need to do it explictly ch = (char)(ch + 1);
This is called Binary Numeric Promotion:
Binary numeric promotion is performed on the operands of certain
operators:
...
The addition and subtraction operators for numeric types + and - (§15.18.2)
and it will perform
Widening primitive conversion (§5.1.2) is applied to convert either or
both operands as specified by the following rules:
If either operand is of type double, the other is converted to double.
Otherwise, if either operand is of type float, the other is converted
to float.
Otherwise, if either operand is of type long, the other is converted
to long.
Otherwise, both operands are converted to type int.
By ch+1
, the char ch
will be promoted to int
first, just like ((int)ch) + 1
, so the result will be an int
.
When you try assign an int
(32 bit) back to a char
(16 bit), it might loss accuracy, you need to do it explictly ch = (char)(ch + 1);
This is called Binary Numeric Promotion:
Binary numeric promotion is performed on the operands of certain
operators:
...
The addition and subtraction operators for numeric types + and - (§15.18.2)
and it will perform
Widening primitive conversion (§5.1.2) is applied to convert either or
both operands as specified by the following rules:
If either operand is of type double, the other is converted to double.
Otherwise, if either operand is of type float, the other is converted
to float.
Otherwise, if either operand is of type long, the other is converted
to long.
Otherwise, both operands are converted to type int.
edited 4 hours ago
answered 4 hours ago
孙兴斌
15.8k41644
15.8k41644
add a comment |
add a comment |
up vote
2
down vote
First of all, note that a char
is 2 bytes large (16 bit), and an int
is 32bit.
1. When typing ch++
:
to apply the ++
operator, there is no type cast but the operator simply causes the bit represent of that char
to increase by 1 to itself. Refer to JLS11 chapter 15.14.2,page 575:
The type of the postfix increment expression is the type of the variable.
2. When typing ch=ch+1
:
ch
is firstly casted to int
, then it is added by 1
(still an int), and the =
is actually tring to cast the int
which has 32bits into a char
which has only 16
bits, note that this may lose accuracy. So without an explicitly cast, the compiler will complain about that, which is the cause of the error.
I did not understand the no. 1 point .if ch is casted into int when printing the value of ch after ch++; operation why it shows character instead of int.. Can You plz explain the first term details
– Tushar Mia
1 hour ago
1
[sorry for my bad English ] I mean : suppose at first I assign 'A' into ch .after I do the ch++; operation. here if ch would cast into int and then add value 1 . here corresponding Unicode value of A which is 65 then add 1 .total 66 so after when I perform the action System.out.print("character "+ch); it should show the output like this : character 66 . that all I understood from your second comment . the I asked you that why the output is character B if ch is casted into int then add int value 1
– Tushar Mia
30 mins ago
Thanks for pointing it out. Updated my post @Tushar Mia
– ZhaoGang
29 mins ago
what does it mean by ''the bit represent of that char"
– Tushar Mia
19 mins ago
By saying that I mean the value of that char, and that value is stored in the memory by a set of bits(16 bits)
– ZhaoGang
2 mins ago
|
show 1 more comment
up vote
2
down vote
First of all, note that a char
is 2 bytes large (16 bit), and an int
is 32bit.
1. When typing ch++
:
to apply the ++
operator, there is no type cast but the operator simply causes the bit represent of that char
to increase by 1 to itself. Refer to JLS11 chapter 15.14.2,page 575:
The type of the postfix increment expression is the type of the variable.
2. When typing ch=ch+1
:
ch
is firstly casted to int
, then it is added by 1
(still an int), and the =
is actually tring to cast the int
which has 32bits into a char
which has only 16
bits, note that this may lose accuracy. So without an explicitly cast, the compiler will complain about that, which is the cause of the error.
I did not understand the no. 1 point .if ch is casted into int when printing the value of ch after ch++; operation why it shows character instead of int.. Can You plz explain the first term details
– Tushar Mia
1 hour ago
1
[sorry for my bad English ] I mean : suppose at first I assign 'A' into ch .after I do the ch++; operation. here if ch would cast into int and then add value 1 . here corresponding Unicode value of A which is 65 then add 1 .total 66 so after when I perform the action System.out.print("character "+ch); it should show the output like this : character 66 . that all I understood from your second comment . the I asked you that why the output is character B if ch is casted into int then add int value 1
– Tushar Mia
30 mins ago
Thanks for pointing it out. Updated my post @Tushar Mia
– ZhaoGang
29 mins ago
what does it mean by ''the bit represent of that char"
– Tushar Mia
19 mins ago
By saying that I mean the value of that char, and that value is stored in the memory by a set of bits(16 bits)
– ZhaoGang
2 mins ago
|
show 1 more comment
up vote
2
down vote
up vote
2
down vote
First of all, note that a char
is 2 bytes large (16 bit), and an int
is 32bit.
1. When typing ch++
:
to apply the ++
operator, there is no type cast but the operator simply causes the bit represent of that char
to increase by 1 to itself. Refer to JLS11 chapter 15.14.2,page 575:
The type of the postfix increment expression is the type of the variable.
2. When typing ch=ch+1
:
ch
is firstly casted to int
, then it is added by 1
(still an int), and the =
is actually tring to cast the int
which has 32bits into a char
which has only 16
bits, note that this may lose accuracy. So without an explicitly cast, the compiler will complain about that, which is the cause of the error.
First of all, note that a char
is 2 bytes large (16 bit), and an int
is 32bit.
1. When typing ch++
:
to apply the ++
operator, there is no type cast but the operator simply causes the bit represent of that char
to increase by 1 to itself. Refer to JLS11 chapter 15.14.2,page 575:
The type of the postfix increment expression is the type of the variable.
2. When typing ch=ch+1
:
ch
is firstly casted to int
, then it is added by 1
(still an int), and the =
is actually tring to cast the int
which has 32bits into a char
which has only 16
bits, note that this may lose accuracy. So without an explicitly cast, the compiler will complain about that, which is the cause of the error.
edited 28 mins ago
answered 4 hours ago
ZhaoGang
958814
958814
I did not understand the no. 1 point .if ch is casted into int when printing the value of ch after ch++; operation why it shows character instead of int.. Can You plz explain the first term details
– Tushar Mia
1 hour ago
1
[sorry for my bad English ] I mean : suppose at first I assign 'A' into ch .after I do the ch++; operation. here if ch would cast into int and then add value 1 . here corresponding Unicode value of A which is 65 then add 1 .total 66 so after when I perform the action System.out.print("character "+ch); it should show the output like this : character 66 . that all I understood from your second comment . the I asked you that why the output is character B if ch is casted into int then add int value 1
– Tushar Mia
30 mins ago
Thanks for pointing it out. Updated my post @Tushar Mia
– ZhaoGang
29 mins ago
what does it mean by ''the bit represent of that char"
– Tushar Mia
19 mins ago
By saying that I mean the value of that char, and that value is stored in the memory by a set of bits(16 bits)
– ZhaoGang
2 mins ago
|
show 1 more comment
I did not understand the no. 1 point .if ch is casted into int when printing the value of ch after ch++; operation why it shows character instead of int.. Can You plz explain the first term details
– Tushar Mia
1 hour ago
1
[sorry for my bad English ] I mean : suppose at first I assign 'A' into ch .after I do the ch++; operation. here if ch would cast into int and then add value 1 . here corresponding Unicode value of A which is 65 then add 1 .total 66 so after when I perform the action System.out.print("character "+ch); it should show the output like this : character 66 . that all I understood from your second comment . the I asked you that why the output is character B if ch is casted into int then add int value 1
– Tushar Mia
30 mins ago
Thanks for pointing it out. Updated my post @Tushar Mia
– ZhaoGang
29 mins ago
what does it mean by ''the bit represent of that char"
– Tushar Mia
19 mins ago
By saying that I mean the value of that char, and that value is stored in the memory by a set of bits(16 bits)
– ZhaoGang
2 mins ago
I did not understand the no. 1 point .if ch is casted into int when printing the value of ch after ch++; operation why it shows character instead of int.. Can You plz explain the first term details
– Tushar Mia
1 hour ago
I did not understand the no. 1 point .if ch is casted into int when printing the value of ch after ch++; operation why it shows character instead of int.. Can You plz explain the first term details
– Tushar Mia
1 hour ago
1
1
[sorry for my bad English ] I mean : suppose at first I assign 'A' into ch .after I do the ch++; operation. here if ch would cast into int and then add value 1 . here corresponding Unicode value of A which is 65 then add 1 .total 66 so after when I perform the action System.out.print("character "+ch); it should show the output like this : character 66 . that all I understood from your second comment . the I asked you that why the output is character B if ch is casted into int then add int value 1
– Tushar Mia
30 mins ago
[sorry for my bad English ] I mean : suppose at first I assign 'A' into ch .after I do the ch++; operation. here if ch would cast into int and then add value 1 . here corresponding Unicode value of A which is 65 then add 1 .total 66 so after when I perform the action System.out.print("character "+ch); it should show the output like this : character 66 . that all I understood from your second comment . the I asked you that why the output is character B if ch is casted into int then add int value 1
– Tushar Mia
30 mins ago
Thanks for pointing it out. Updated my post @Tushar Mia
– ZhaoGang
29 mins ago
Thanks for pointing it out. Updated my post @Tushar Mia
– ZhaoGang
29 mins ago
what does it mean by ''the bit represent of that char"
– Tushar Mia
19 mins ago
what does it mean by ''the bit represent of that char"
– Tushar Mia
19 mins ago
By saying that I mean the value of that char, and that value is stored in the memory by a set of bits(16 bits)
– ZhaoGang
2 mins ago
By saying that I mean the value of that char, and that value is stored in the memory by a set of bits(16 bits)
– ZhaoGang
2 mins ago
|
show 1 more comment
Tushar Mia is a new contributor. Be nice, and check out our Code of Conduct.
Tushar Mia is a new contributor. Be nice, and check out our Code of Conduct.
Tushar Mia is a new contributor. Be nice, and check out our Code of Conduct.
Tushar Mia is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53791297%2fwhy-cant-i-write-ch-ch1-instead-of-ch-though-they-have-same-meaning%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Welcome to Stack Overflow! Please have a look around, and read through the help center, in particular How do I ask a good question? "but why is here occur error" Always quote the exact error, rather than just saying you get an error. In this case, we can probably guess what error you're talking about, but you don't want to make the people trying to help you guess.
– T.J. Crowder
4 hours ago
It’s a confusing behaviour that has been taken over from C++ and its forerunners.
– Ole V.V.
4 hours ago
2
an
int
plus achar
is anint
– Peter Lawrey
3 hours ago
Note that Java is one of the few languages that actually retains a distinct character type from C, in most languages characters are actually strings and won't compile (or will throw a runtime error) if you try to treat them as integers.
– Jared Smith
2 hours ago
@Tushar Mia : What should I do when someone answers my question?
– Nicholas K
38 mins ago