0% found this document useful (0 votes)
19 views3 pages

Public Class JaggedArrayExample

The document contains three Java programs: the first demonstrates the use of a jagged array, initializing it with varying lengths and displaying its elements. The second program creates a graphical application to draw a smiley face using JavaFX. The third program checks if a user-inputted integer is a prime number, implementing a method to determine primality.

Uploaded by

dehoce7350
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)
19 views3 pages

Public Class JaggedArrayExample

The document contains three Java programs: the first demonstrates the use of a jagged array, initializing it with varying lengths and displaying its elements. The second program creates a graphical application to draw a smiley face using JavaFX. The third program checks if a user-inputted integer is a prime number, implementing a method to determine primality.

Uploaded by

dehoce7350
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

public class JaggedArrayExample {

public static void main(String[] args) {

// Declare a 2D jagged array with 3 rows

int[][] jaggedArray = new int[3][];

// Initialize each row with different number of columns

jaggedArray[0] = new int[]{1, 2};

jaggedArray[1] = new int[]{3, 4, 5};

jaggedArray[2] = new int[]{6};

// Display the elements of the jagged array

for (int i = 0; i < [Link]; i++) {

for (int j = 0; j < jaggedArray[i].length; j++) {

[Link](jaggedArray[i][j] + " ");

[Link]();

Smiley Face

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];

import [Link];
public class SmileyFaceApp extends Application {

@Override

public void start(Stage stage) {

// Face

Circle face = new Circle(150, 150, 100);

[Link]([Link]);

[Link]([Link]);

// Eyes

Circle leftEye = new Circle(110, 120, 10);

Circle rightEye = new Circle(190, 120, 10);

// Smile (Arc)

Arc smile = new Arc(150, 170, 50, 30, 180, 180);

[Link]([Link]);

[Link]([Link]);

[Link](null);

[Link](3);

Group root = new Group(face, leftEye, rightEye, smile);

Scene scene = new Scene(root, 300, 300, [Link]);

[Link]("Smiley Face");

[Link](scene);

[Link]();

public static void main(String[] args) {

launch(args);

}
import [Link];

public class PrimeCheck {

public static void main(String[] args) {

Scanner scanner = new Scanner([Link]);

[Link]("Enter a positive integer: ");

int num = [Link]();

if (isPrime(num)) {

[Link](num + " is a prime number.");

} else {

[Link](num + " is not a prime number.");

[Link]();

public static boolean isPrime(int n) {

if (n <= 1) return false;

if (n == 2) return true;

// Check from 2 to sqrt(n)

for (int i = 2; i <= [Link](n); i++) {

if (n % i == 0) return false;

return true;

You might also like