Identify and fix the errors in the following code.
1 public class Test {
2 public void main(string[] args) {
3 int i ;
4 int k = 100.0;
5 int j = i + 1;
6
7 System.out.println(“j is ” + j + ” and
8 k is ” + k);
9 }
10 }
Actual Program Now
Errors In The Java Program
- Line 2: Static Keyword is Missing for the Main Method.
- Line 2: String is a Keyword so, S of string should be capital.
- Line 3: Variable i is defined but it is not initialized anywhere for usage.
- Line 4: Variable k is an int type. It can’t store double type in this syntax.
- Lines 7-8: Data Type String can not be split into two lines without concatenation operator.
For any confusion, do not forget to ask it using comments.
0 responses :
Post a Comment