Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Alphabets {
- public static void main(String[] args) throws Throwable {
- final AN an = new AN(false);
- new Thread(an::Alpha).start();
- new Thread(an::numbers).start();
- }
- }
- class AN {
- boolean flag;
- AN(boolean flag) {
- this.flag = flag;
- }
- synchronized void Alpha() {
- for (char i = 'A'; i <= 'Z'; i++) {
- if (flag == false) {
- System.out.print(+i + " ");
- notifyAll();
- flag = true;
- }
- if (i != 'Z') {
- try {
- wait();
- } catch (InterruptedException ex) {
- }
- }
- }
- }
- synchronized void numbers() {
- for (int i = 1; i <= 26; i++) {
- if (flag == true) {
- System.out.print(+i + " ");
- notifyAll();
- flag = false;
- }
- if (i != 26) {
- try {
- wait();
- } catch (InterruptedException ex) {
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment