@@ -1379,6 +1379,92 @@ Output
13791379```
13801380-13 9 -3 10 -5 6 -7 2 -12 1 -11 14 -4 -8
13811381```
1382+ #### Q. How Convert lower to upper case without using toUppercase() in java?
1383+
1384+ ``` java
1385+ /**
1386+ * Java program to Convert lower to upper case
1387+ *
1388+ **/
1389+ public class toLowerCase {
1390+
1391+ public static void main (String [] args ) {
1392+ toLowerCase(args[0 ]);
1393+ }
1394+
1395+ public static void toLowerCase (String a ) {
1396+
1397+ for (int i = 0 ; i< a. length(); i++ ) {
1398+ char aChar = a. charAt(i);
1399+ if (65 <= aChar && aChar<= 90 ) {
1400+ aChar = (char )( (aChar + 32 ) );
1401+ }
1402+ System . out. print(aChar);
1403+ }
1404+ }
1405+ }
1406+ ```
1407+ #### Q. Explain deadlock condition in-between two threads with example?
1408+
1409+ ``` java
1410+ public class DeadLockSimulator {
1411+
1412+ public static Object Lock1 = new Object ();
1413+ public static Object Lock2 = new Object ();
1414+
1415+ private static class FirstThread extends Thread {
1416+ public void run () {
1417+ synchronized (Lock1 ) {
1418+ System . out. println(" Thread 1: Holding lock 1..." );
1419+ try { Thread . sleep(10 ); } catch (Exception e) {}
1420+ System . out. println(" Thread 1: Waiting for lock 2..." );
1421+ synchronized (Lock2 ) {
1422+ System . out. println(" Thread 1: Holding lock 1 & 2..." );
1423+ }
1424+ }
1425+ }
1426+ }
1427+
1428+ private static class SecondThread extends Thread {
1429+ public void run () {
1430+ synchronized (Lock2 ) {
1431+ System . out. println(" Thread 2: Holding lock 2..." );
1432+ try { Thread . sleep(10 ); } catch (Exception e) {}
1433+ System . out. println(" Thread 2: Waiting for lock 1..." );
1434+ synchronized (Lock1 ) {
1435+ System . out. println(" Thread 2: Holding lock 1 & 2..." );
1436+ }
1437+ }
1438+ }
1439+ }
1440+
1441+ public static void main (String args []) {
1442+
1443+ new FirstThread (). start();
1444+ new SecondThread (). start();
1445+ }
1446+ }
1447+ ```
1448+ Output:
1449+ ``` java
1450+ " Thread-1" prio= 6 tid= 0x0000000007319000 nid= 0x7cd3c waiting for monitor entry [0x0000000008a3f000 ]
1451+ java.lang. Thread . State : BLOCKED (on object monitor)
1452+ at com.tier1app. DeadLockSimulator $SecondThread . run(DeadLockSimulator . java: 29 )
1453+ - waiting to lock 0x00000007ac3b1970 (a java.lang. Object )
1454+ - locked 0x00000007ac3b1980 (a java.lang. Object )
1455+
1456+ Locked ownable synchronizers:
1457+ - None
1458+
1459+ " Thread-0" prio= 6 tid= 0x0000000007318800 nid= 0x7da14 waiting for monitor entry [0x000000000883f000 ]
1460+ java.lang. Thread . State : BLOCKED (on object monitor)
1461+ at com.tier1app. DeadLockSimulator $FirstThread . run(DeadLockSimulator . java: 16 )
1462+ - waiting to lock 0x00000007ac3b1980 (a java.lang. Object )
1463+ - locked 0x00000007ac3b1970 (a java.lang. Object )
1464+
1465+ Locked ownable synchronizers:
1466+ - None
1467+ ```
13821468#### Q. How to find if there is a sub array with sum equal to zero?
13831469#### Q. How to remove a given element from array in Java?
13841470#### Q. How to find trigonometric values of an angle in java?
0 commit comments