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

Final Exam

Uploaded by

Zojaan Aheer
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)
17 views3 pages

Final Exam

Uploaded by

Zojaan Aheer
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
You are on page 1/ 3

Q2.

public class Test{

public static void main(String[] args) {

int arr[][] = new int[][]{{2,3,4,8},{1,3,6,4},{4,2,9,3}};

displayAppearance(arr);

public static void displayAppearance(int[][] arr){

for (int i = 1; i < 9; i++) {

int count = 0;

for (int j = 0; j < arr.length; j++) {

for (int k = 0; k < arr[j].length; k++) {

if (i == arr[j][k]) {

count++;

if (count > 0) {

System.out.println("The value " + i + " appears " + count + " times.");

}
3.
public class Test{

public static void main(String[] args) {

String s = "abbbbbacaaaaaaaaacccafffdddddddd";

displayMax(s);

public static void displayMax(String s) {

int max = 0;

for (int i = 0; i < s.length(); i++) {

int count = 1;

for (int j = i; j < s.length(); j++) {

if (s.charAt(i) == s.charAt(j)) {

if (++count > max) {

max = count;

} else {

i = j;

break;

System.out.println("\nMax : " + max);

4.
public class Test{

public static void main(String[] args) {

You might also like