Can I get the answer of; | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can I get the answer of;

public class Program { public static void main(String[] args) { int num1 = 4; int num2 = 8; num2 += num1; System.out.println(num2); } }

31st Aug 2020, 4:32 AM
SATVIK Jain
SATVIK Jain - avatar
20 Answers
0
Ya only ints
31st Aug 2020, 4:42 AM
SATVIK Jain
SATVIK Jain - avatar
+ 7
Satvik Jain If you are asking this part that you don't understand I think it should be like that Line 3 coverts num1, string to numerical by using int. If we don't covert 4 to numerical it will remain a string. Same done in the below line. In the third line you have added both the digits by + symbol. In the last step you have used system.out.printin it is used for printing the results. Hope this helps🤟
31st Aug 2020, 4:38 AM
Piyush
Piyush - avatar
+ 7
This is simple problem addition of two numbers and your code is working fine and Output giving 12 . Don't post unnecessary questions you can also run on solo playground. If you have doubts in question then u can ask .
31st Aug 2020, 5:01 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 6
Tibor Santa Seems like my explanation is same. Isn't it. Do I have missed and part in it?
31st Aug 2020, 4:40 AM
Piyush
Piyush - avatar
+ 6
Tibor Santa If we don't use int method then do the num1=4 will be automatically be string? Or do it will be changed according to the num?
31st Aug 2020, 4:43 AM
Piyush
Piyush - avatar
+ 6
Satvik Jain Escuse me? I'm not fighting dude. I'm just clearing my doubt from Tibor sir. Because I too have a confusion..(likely same)
31st Aug 2020, 4:47 AM
Piyush
Piyush - avatar
+ 4
piyush there are no strings involved here. Both variables are declared as int.
31st Aug 2020, 4:42 AM
Tibor Santa
Tibor Santa - avatar
+ 3
What is your question? Just run it in the code playground and see the result.
31st Aug 2020, 4:34 AM
Tibor Santa
Tibor Santa - avatar
+ 3
Assign value 4 to variable num1 Assign value 8 to variable num2 Increment num2 by num1 this can be written as: num2 = num2 + num1; So num2 becomes 8+4=12
31st Aug 2020, 4:37 AM
Tibor Santa
Tibor Santa - avatar
+ 3
int num1 = 4; int is not a method, it is the type of the variable. We use int for numbers so that we can do math operations on them (like addition). Inside the print statement, the number is automatically converted to String.
31st Aug 2020, 5:01 AM
Tibor Santa
Tibor Santa - avatar
+ 3
Hey buddy, Nobody can help but your study and learning can help you And asking questions which doesn't help everybody and doesn't allows you to learn anything again can be called a spam. Try searching before asking questions. And chatting in someone's post is also a spam guys.
31st Aug 2020, 7:43 AM
Raj Srivastava
Raj Srivastava - avatar
+ 2
In python types are implicit. ... Switch now 🍻
31st Aug 2020, 1:42 PM
Sanjay Kamath
Sanjay Kamath - avatar
+ 2
Try it on code playgroud...its better to you than posting here
2nd Sep 2020, 3:13 AM
👑Mahesh Khatri👑
👑Mahesh Khatri👑 - avatar
+ 1
But I don't understand it
31st Aug 2020, 4:34 AM
SATVIK Jain
SATVIK Jain - avatar
+ 1
Thanks guys 😃😃
31st Aug 2020, 4:39 AM
SATVIK Jain
SATVIK Jain - avatar
+ 1
Please don't fight😭
31st Aug 2020, 4:45 AM
SATVIK Jain
SATVIK Jain - avatar
+ 1
The answer is 12. Why? : Because num2+=num1 mean add num2 to num1 To be num2=num2+num1.
1st Sep 2020, 11:39 AM
Fareed
Fareed - avatar
0
Ok thanks
31st Aug 2020, 4:38 AM
SATVIK Jain
SATVIK Jain - avatar
0
Ok sorry 😖
31st Aug 2020, 4:47 AM
SATVIK Jain
SATVIK Jain - avatar
0
No it needs system, vertual machine(VM), java compiler, java VM library as well as java runtime environment. Be Cautious about this kind of questions... DHANANJAY PATEL
2nd Sep 2020, 2:51 AM
DHANANJAY PATEL
DHANANJAY PATEL - avatar