Here's the answer the Q1 in Java.
Code:
import java.io.*;
public class exam {
private static String input = "";
private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
/**
* *Constructor
*/
public static void main(String[] args) {
*
*int x = -999;
*int y = -999;
*
*try {
* x = getNumber("x");
* y = getNumber("y");
* in.close();
*}
*catch(IOException ex) {
* ex.printStackTrace();
*}
*
*System.out.print("second_root_of(x*x+y*y) is ");
*System.out.println(secondRootOf(x,y));
*
}
/**
* Function secondRootOf(int , int)
*
* @return int
*/
private static int secondRootOf(int x, int y)
{
*return x*x+y*y;
}
/**
* *Function getNumber(String)
* *
* *@exception NumberFormatException
* *@throws IOException
* *@return int
*/
private static int getNumber(String which) throws IOException
{
*boolean stop = false;
*int num = 0;
*
*while(!stop) {
*
* try {
* *System.out.print("Enter "+which+": ");
* *input = in.readLine();
* *num = Integer.parseInt(input);
* *
* *if(num < 0) {
* * num = num*-1;
* *}
*
* *stop = true;
* }
* catch(NumberFormatException nfe) {
* *System.out.println("Not a valid integer, try again");
* *stop = false;
* }
*}
*
*return num;
}
}//end class