Page 279 - IT-802_class_12
P. 279
28. Write a program in Java to print the average of the first ten numbers. [2022]
Ans. import java.util.Scanner; //program uses Scanner class
public class Average
{
public static void main(String[] args)
{
int n,num,sum=0, i;
//create scanner object to obtain input from keyboard
Scanner input =new Scanner(System.in);
System.out.print(“Enter How many Numbers : “);//input
n =input.nextint(); //read total numbers
System.out.print(“Enter the Numbers :”);
for(i=1;i<=n; i++)
{
num=input.nextint(); //input number
sum += num;
}
double average=(double)sum/n;
System.out.println(“Average of “ + n + “ Numbers = “ +
average);
}
}
29. (a) Explain wait() method in Java threads. [2022]
(b) Explain setPriority() method in Java and give the range of priority levels.
Ans. (a) wait() causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this
object. In other words, this method behaves exactly as if it simply performs the call wait(0). The current thread must
own this object’s monitor.
(b) The setPriority() method of thread class is used to change the thread’s priority. Every thread has a priority which is
represented by the integer number between 1 to 10. Thread class provides 3 constant properties: public static int
MIN_PRIORITY: It is the maximum priority of a thread.
30. Consider the following class: [2022]
public class Stud {
String Rno;
String Sname;
String Address;
double marks;
void display()
{ System.out.printin(“Rno : “ + Rno):
System.out.printin(“Student name : “ + Sname);
System.out.printin(“Address : “ + Address);
System.out.printin(“marks : “ + marks): }
};
Fundamentals of Java Programming 277

