In: Computer Science
Identify errors and correct them of the following Java program:
1. import java.utility.Random;
2.
3. public class Sequen
4.
5. private int stand
6. private int calc;
7.
8. public Sequen(int numStand)
9. {
10. stand = numStand;
11. skip;
12. }
13.
14. public void skip()
15. {
16. Random sit = new Random();
17. calc = sit.nextInt(stand) + 1;
18. }
19.
20. public getStand()
21. {
22. return stand;
23. }
24.
25. int getCalc()
26. {
27. return calc;
28. }
29. }
Identify 5 other errors and give their Line Number, Error description and Statement after correction.
it is the corrected code for above code:-
code:-
import java.util.Random;
public class Sequen
{
private int stand ;
private int calc;
public Sequen(int numStand)
{
stand = numStand;
skip();
}
public void skip()
{
Random sit = new Random();
calc = sit.nextInt(stand) + 1;
}
public int getStand()
{
return stand;
}
int getCalc()
{
return calc ;
}
}
code:-
import java.util.Random;
public class Sequen
{
private int stand ;
private int calc;
public Sequen(int numStand)
{
stand = numStand;
skip();
}
public void skip()
{
Random sit = new Random();
calc = sit.nextInt(stand) + 1;
}
public int getStand()
{
return stand;
}
int getCalc()
{
return calc ;
}
public static void main(String args[])
{
Sequen sc=new Sequen(5);
System.out.println(sc.getCalc()); //it generate a random number between a given numstand +1
System.out.println(sc.getStand()); // it give the numstand value
}
}
output:-
4
5