0% found this document useful (0 votes)
24 views1 page

Java OOPS Lab: Prime & Jagged Array

The document contains Java programs demonstrating the use of command line arguments to check for prime numbers and the implementation of a jagged array. The first program outputs whether a given number is prime, while the second program prints the elements of a jagged array. Example outputs for both programs are provided.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views1 page

Java OOPS Lab: Prime & Jagged Array

The document contains Java programs demonstrating the use of command line arguments to check for prime numbers and the implementation of a jagged array. The first program outputs whether a given number is prime, while the second program prints the elements of a jagged array. Example outputs for both programs are provided.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

OOPS Using Java Lab (BCS-452) - Programs with Output

1. Prime Number using Command Line Argument


public class PrimeCheck {
public static void main(String[] args) {
int num = [Link](args[0]);
boolean isPrime = true;
if (num <= 1) isPrime = false;
for (int i = 2; i <= [Link](num); i++) {
if (num % i == 0) {
isPrime = false;
break;
}
}
[Link](num + (isPrime ? " is Prime" : " is not Prime"));
}
}

Output:
7 is Prime

2. Jagged Array
public class JaggedArray {
public static void main(String[] args) {
int[][] arr = new int[3][];
arr[0] = new int[]{1, 2};
arr[1] = new int[]{3, 4, 5};
arr[2] = new int[]{6};
for (int[] row : arr) {
for (int val : row) {
[Link](val + " ");
}
[Link]();
}
}
}

Output:
1 2
3 4 5
6

You might also like