To pass an integer by reference in Java, try the following code −Example Live Demopublic class Demo { public static void display(int[] arr) { arr[0] = arr[0] + 50;; } public static void main(String[] args) { int val = 50; int[] myArr = { val }; display(myArr); System.out.println(myArr[0]); } }Output100In the above program, a custom method is created, which pass an int array.int val = 50; int[] myArr = { val }; display(myArr);In the method, we have performed mathematical operation on the value of array.public static void display(int[] arr) { arr[0] = arr[0] + 50;; }The updated value is then displayed in the main.System.out.println(myArr[0]);
To compare two Java short arrays, use the Arrays.equals() method.Let us first declare and initialize some int arrays.int[] arr1 = new int[] { 33, 66, 12, 56, 99 }; int[] arr2 = new int[] { 33, 66, 12, 56, 99 }; int[] arr3 = new int[] { 33, 66, 15, 56, 90 };Now let us compare any two of the above arrays.Arrays.equals(arr1, arr2));In the same way, work it for other arrays and compare themExample Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { int[] arr1 = new int[] { 33, 66, 12, 56, ... Read More
To reverse an integer in Java, try the following code −Example Live Demoimport java.lang.*; public class Demo { public static void main(String[] args) { int i = 239, rev = 0; System.out.println("Original: " + i); while(i != 0) { int digit = i % 10; rev = rev * 10 + digit; i /= 10; } System.out.println("Reversed: " + rev); } }OutputOriginal: 239 Reversed: 932In the above program, we have the following int value, which we will reverse.int i = 239;Now, loop through until the value is 0. Find the remainder and perform the following operations to get the reverse of the given integer 239.while(i != 0) { int digit = i % 10; rev = rev * 10 + digit; i /= 10; }
Now let us see a program of Intel 8085 Microprocessor. This program will convert HEX to ASCII values.Problem StatementWrite 8085 Assembly language programs to convert Hexadecimal characters to ASCII values.DiscussionWe know that the ASCII of number 00H is 30H (48D), and ASCII of 09H is39H (57D). So all other numbers are in the range 30H to 39H. The ASCII value of 0AH is 41H (65D) and ASCII of 0FH is 46H (70D), so all other alphabets (B, C, D, E, F) are in the range 41H to 46H.Here we are providing hexadecimal digit at memory location 8000H, The ASCII equivalent ... Read More
To assign int value to a char variable in Java would consider the ASCII value and display the associated character/ digit.Here, we have a char.char val;Now assign int value to it.val = 77;Now, when you will print the value of “val”, it would display the character associate with the value (ASCII) 77.The following is the complete example.Example Live Demopublic class Demo { public static void main(String []args) { char val; val = 77; System.out.print("Value: "); System.out.println(val); } }OutputValue: M
Now let us see a program of Intel 8085 Microprocessor. This program is mainly for finding a square of a number.Problem StatementWrite 8085 Assembly language program to find the square of a number using Look-Up Table. DiscussionIn this example, we are using Look-Up table to find the square of a number. The main limitation of this program is that it can find a square in range 0-F. When the input is above F, it will fail. We are storing the square result into the memory. When the number is greater than F, we are storing FFH into memory to indicate an ... Read More
There are some words in Hindi, which are beautiful and cannot be translated into English. We can only describe the meaning of the word in a sentence but there are no exact replacements in English. In India, we use some Hindi words as it is even in our English documents to keep up their sanctity.Viraha - the realization of love through separationAkashvani - celestial announcement ( voice from skies)Maya - The illusion or deceptive appearance of this physical world. Acts of God which cannot be understood by humans.Pushpanjali - Pushpa- flowers; Anjali - folded hands - Folded hands with full ... Read More
To convert decimal to hexadecimal, use any of the two methods i.e.Integer.toHexString() − It returns a string representation of the integer argument as an unsigned integer in base 16.Integer.parseInt() − It allows you to set the radix as well, for example, for hexadecimal set it as 16.Let us see an example now to convert decimal to hexadecimal using Integer.toHexString() method.Example Live Demopublic class Demo { public static void main( String args[] ) { int dec = 158; System.out.println(Integer.toHexString(dec)); } }Output9eLet us see an example now to convert decimal to hexadecimal using Integer.parseInt() method.Example Live ... Read More
To convert a string to a number in Java, use the Integer.parseInt() method. First, let use create a String and set value.String str = "45";Now, take an Integer and use the Integer.parseInt() method.Integer i = Integer.parseInt(str);Let us see the complete example.Example Live Demopublic class Demo { public static void main( String args[] ) { String str = "45"; Integer i = Integer.parseInt(str); System.out.println("Num: " + i); } }OutputNum: 45
Use the valueOf() method to convert boolean value to Boolean. Firstly, let us take a boolean value.boolean val = false;Now, to convert it to Boolean object, use the valueOf() method.Boolean res = Boolean.valueOf(val);Let us now see the complete example to convert boolean value to Boolean.Example Live Demopublic class Demo { public static void main(String[] args) { boolean val = false; System.out.println("Boolean Value = "+val); Boolean res = Boolean.valueOf(val); System.out.println("Boolean = " + res); if (res.equals(Boolean.TRUE)) { System.out.println("Boolean = " + res); ... Read More