Page 289 - COPA VOL II of II - TP -Punjabi
P. 289
ਿਾਪਸੀ: ਉਦਾਹ੍ਨ 3
byteValue() ਿਭਧੀ ਮੁੱਢਲੀ ਬਾਈਟ ਕਭਸਮ ਿਭੱਚ ਪਰਭਿਰਤਨ ਤੋਂ ਬਾਅਦ ਇਸ 1 import java.io.IOException;
ਿਸਤੂ ਦੁਆਰਾ ਦਰਸਾਏ ਗਏ ਸੰਖਭਆਤਮਕ ਮੁੱਲ ਨੂੰ ਿਾਪਸ ਕਰਦੀ ਹੈ। 2 import java.util.Scanner;
ਅਨੁਕੂਲਤਾ ਸੰਸਕਰਣ: 3 public class NumberByteValueExample3 {
4 public s tatic void main(String[] args)throws
Java 1.1 ਅਤੇ ਇਸਤੋਂ ਉੱਪਰ IOException {
ਉਦਾਹ੍ਨ 1 5 Scanner scan = new Scanner(System.in);
1 public class NumberByteValueExample1 { 6 System.out.print(“Enter the Number Value: “);
2 public static void main(String[] args) { 7 Integer num = scan.nextInt();
3 Integer i = 123456; 8 //Convert number value into byte type
4 //Convert number value into byte type 9 System.out.println(“Integer Number as Byte: “+num.
byteValue());
5 int Result = i.byteValue();
10 scan.close();
6 System.out.println(“Number as Byte: “+Result);
11 }
7 }
12 }
8 }
Output:
Output:
Enter the Number Value: ABCDEF
Number as Byte: 64
Exception in t hread “ main” java.util.
InputMismatchException
ਉਦਾਹ੍ਨ 2
at java.base/java.util.Scanner.throwFor(Scanner.
1 public class NumberByteValueExample2 {
java:939)
2 public static void main(String[] args) {
a t java.base/java.util.Scanner.next(Scanner.
3 Integer i = -123456; java:1594)
4 Float f = 435f; a t java.base/java.util.Scanner.nextInt(Scanner.
5 Double d = 65868.685; java:2258)
at java.base/java.util.Scanner.nextInt(Scanner.
6 //Convert number value into byte type
java:2212)
7 System.out.println(“Integer Number a s Byte: “+i. at myPackage.NumberByteValueExample3.
byteValue());
main(NumberByteValueExample3.java:9)
8 System.out.println(“Float N umber a s Byte: “+f.
byteValue());
9 System.out.println(“Double Number a s Byte: “+d.
byteValue());
10 }
11 }
Output:
Integer Number as Byte: -64
Float Number as Byte: -77
Double Number as Byte: 76
IT & ITES - COPA - (NSQF ਸੋਧੇ - 2022) - ਅਿਭਆਸ 1.40.13 275