New course! Every coder should learn Generative AI!
Try a free lesson+ 5
Why am i getting this error?
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.
+ 5
b does not have value assigned to.
What input do you expect? what output do you expect?
+ 3
Did you read when you get some error, what output in console???
error: variable might not have been Intialized.
Learn read first.
+ 2
I think you need to initialize the int b
So replace int s,b; with int a,b = 0;
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
0
Suvan Shenoy
Is this an inappropriate way to write?
but there is no syntax error..
0
Ayush Singh yes its not right but now u have corrected it so keep it up
- 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
- 1
Lisa i was trying to find hcf of two numbers
- 1
Thank you all for helping me✌️
- 1
did u correct your mistake?
- 1
miguel🦋 yes