Why am i getting this error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
12th Jan 2023, 6:54 PM
Ayush Singh
Ayush Singh - avatar
12 Answers
+ 5
The error in this code is that the variable b is declared inside the if statement, but it is used outside of it. The variable b should be declared outside of the if statement.
12th Jan 2023, 8:00 PM
Reza Mardani
Reza Mardani - avatar
+ 5
b does not have value assigned to. What input do you expect? what output do you expect?
12th Jan 2023, 7:17 PM
Lisa
Lisa - avatar
+ 3
Did you read when you get some error, what output in console??? error: variable might not have been Intialized. Learn read first.
13th Jan 2023, 11:16 AM
Smith Welder
Smith Welder - avatar
+ 2
I think you need to initialize the int b So replace int s,b; with int a,b = 0;
12th Jan 2023, 8:45 PM
Hayk
Hayk - avatar
0
bro also you can't do like int num1 = sc.nextInt() or int num2 = sc.nextInt() the correct way is to do like this: int num1,num2; num1 = sc.nextInt() num2 = sc.nextInt() >>>Remember this is not python or ruby
14th Jan 2023, 3:10 PM
Suvan Shenoy
Suvan Shenoy - avatar
0
Suvan Shenoy Is this an inappropriate way to write? but there is no syntax error..
14th Jan 2023, 5:48 PM
Ayush Singh
Ayush Singh - avatar
0
Ayush Singh yes its not right but now u have corrected it so keep it up
12th Feb 2023, 8:37 AM
Suvan Shenoy
Suvan Shenoy - avatar
- 1
Smith Welder Ya i read, it was written that b has not been initiatized but i was confused, that i have given tha value of b in if-else so why it's giving the not initialzed error
13th Jan 2023, 3:05 PM
Ayush Singh
Ayush Singh - avatar
- 1
Lisa i was trying to find hcf of two numbers
13th Jan 2023, 3:09 PM
Ayush Singh
Ayush Singh - avatar
- 1
Thank you all for helping me✌️
13th Jan 2023, 3:10 PM
Ayush Singh
Ayush Singh - avatar
- 1
did u correct your mistake?
14th Jan 2023, 11:30 AM
miguel🦋
miguel🦋 - avatar
- 1
14th Jan 2023, 5:48 PM
Ayush Singh
Ayush Singh - avatar