Interview Question
Country: United States
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author GodOfWar
*/
public class MyThread extends Thread
{
static int n;
public void run()
{
System.out.println("child Thread executing odd/even");
if(n%2==0)
System.out.println("number is even");
else
System.out.println("number is odd");
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
MyThread t=new MyThread();
t.start();
int fact=1;
for(int i=n;i>0;i--)
{
fact=fact*i;
}
System.out.println("Factorial is calculated by main Thread "+fact);
}
}
import java.util.Scanner;
- Lakshya Sharma April 06, 2020/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author GodOfWar
*/
public class MyThread extends Thread
{
static int n;
public void run()
{
System.out.println("child Thread executing odd/even");
if(n%2==0)
System.out.println("number is even");
else
System.out.println("number is odd");
}
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
MyThread t=new MyThread();
t.start();
int fact=1;
for(int i=n;i>0;i--)
{
fact=fact*i;
}
System.out.println("Factorial is calculated by main Thread "+fact);
}
}