Created
August 18, 2021 09:09
-
-
Save xProgrammer-007/431faff559e99c7a536b31e295d23158 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class ThreadingProg { | |
| public static void main (String[] args) { | |
| new Thread(new Runnable() { | |
| @Override | |
| public void run() { | |
| System.out.println("1st Thread spawned"); | |
| int random = (int)(Math.random() * 1000 + 1); | |
| System.out.println("Random number is " + random); | |
| if(random %2 == 0){ | |
| new Thread(new Runnable() { | |
| @Override | |
| public void run() { | |
| System.out.println("2nd Thread spawned"); | |
| System.out.println("Square of " + random + " is = " + random * random); | |
| } | |
| }).start(); | |
| }else{ | |
| new Thread(new Runnable() { | |
| @Override | |
| public void run() { | |
| System.out.println("2nd Thread spawned"); | |
| System.out.println("Cube of " + random + " is = " + random * random * random); | |
| } | |
| }).start(); | |
| } | |
| } | |
| }).start(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment