0% found this document useful (0 votes)
12 views4 pages

Programming Portfolio Shebrizy098 Updated

This document is a programming portfolio by Shabani Hamis Said, showcasing various Java applets, array manipulations, and string operations. It includes code examples for displaying text in applets, summing array elements, finding maximum values, searching for elements, reversing strings, checking for palindromes, and comparing strings. Each section provides the code along with the expected output for clarity.

Uploaded by

shabanihamisi491
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Programming Portfolio Shebrizy098 Updated

This document is a programming portfolio by Shabani Hamis Said, showcasing various Java applets, array manipulations, and string operations. It includes code examples for displaying text in applets, summing array elements, finding maximum values, searching for elements, reversing strings, checking for palindromes, and comparing strings. Each section provides the code along with the expected output for clarity.

Uploaded by

shabanihamisi491
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Programming Portfolio

Prepared by SHABANI HAMIS SAID

Due Date: 20 June 2025

1. Applets
Simple Applet Displaying Text
import [Link];
import [Link];

public class HelloWorldApplet extends Applet {


public void paint(Graphics g) {
[Link]("Hello, Applet World!", 20, 20);
}
}

Output:

Displays: Hello, Applet World! on applet window

Applet with Parameters


import [Link];
import [Link];

public class ParamApplet extends Applet {


String name;

public void init() {


name = getParameter("username");
}

public void paint(Graphics g) {


[Link]("Hello, " + name, 20, 20);
}
}

Output:

Displays: Hello, <username> (e.g., Hello, Alice)


2. Array
Sum of Array Elements
public class ArraySum {
public static void main(String[] args) {
int[] numbers = {5, 10, 15, 20};
int sum = 0;
for (int num : numbers) {
sum += num;
}
[Link]("Sum = " + sum);
}
}

Output:

Sum = 50

Find Maximum Element in Array


public class MaxArray {
public static void main(String[] args) {
int[] arr = {12, 7, 22, 5};
int max = arr[0];
for (int i = 1; i < [Link]; i++) {
if (arr[i] > max) max = arr[i];
}
[Link]("Maximum: " + max);
}
}

Output:

Maximum: 22

Search an Element in Array


public class SearchArray {
public static void main(String[] args) {
int[] arr = {3, 8, 12, 5};
int target = 12;
boolean found = false;
for (int i = 0; i < [Link]; i++) {
if (arr[i] == target) {
found = true;
break;
}
}
if (found) [Link]("Found!");
else [Link]("Not Found!");
}
}

Output:

Found!

3. String
Reverse a String
public class StringReverse {
public static void main(String[] args) {
String input = "Hello";
String reversed = new StringBuilder(input).reverse().toString();
[Link]("Reversed: " + reversed);
}
}

Output:

Reversed: olleH

Check Palindrome
public class PalindromeCheck {
public static void main(String[] args) {
String str = "madam";
String rev = new StringBuilder(str).reverse().toString();
if ([Link](rev)) {
[Link](str + " is a palindrome.");
} else {
[Link](str + " is not a palindrome.");
}
}
}

Output:

madam is a palindrome.

String Comparison
public class StringCompare {
public static void main(String[] args) {
String a = "Hello";
String b = "hello";
[Link]([Link](b)); // false
[Link]([Link](b)); // true
}
}

Output:

false
true

You might also like