CSC103 - Subjective Part (Fall 2020) 1
CSC103 - Subjective Part (Fall 2020) 1
CSC103 - Subjective Part (Fall 2020) 1
package javaapplication36;
import java.util.Scanner;
int a = Input.nextInt();
int b = Input.nextInt();
int num1=0;
int num2;
if (a > b)
Page 1 of 9
num1 = b;
if (a < b)
num1 = a;
num2 = num1/2;
break;
num2 -= 1;
package javaapplication37;
import java.util.Scanner;
Page 2 of 9
public static void main(String[] args) {
System.out.println();
if (num2 != 0)
else
return num1;
Call stack
Page 3 of 9
Example 2:
Iterative implementation
package javaapplication39;
int num = 6;
int fact = 1;
fact = fact * i;
package javaapplication38;
Page 4 of 9
public static void main(String[] args) {
int out;
if(n==1){
return 1;
out = fact(n-1)* n;
return out;
Call stack
Page 5 of 9
Code an application that displays the number of times a value appears in a two-dimensional array. It displays the
number of times each of the numbers from 1 through 9 appears in the numbers array.
Example: Suppose the user entered the following array.
1 2 7
2 2 2
1 1 7
package javaapplication36;
Page 6 of 9
Question 03 – Strings Points: 04
Given a string, determine the length of the widest/biggest fragment, where all the characters of the fragment are same.
Example: abbbbacacccafffd
Output: 4
package javaapplication41;
Page 7 of 9
}
}
import java.util.*;
import java.io.*;
public class JavaApplication42 {
try (
Page 8 of 9
for (int i = 0; i < 25; i++) {
output.print(((int)(Math.random() * 10000) + 1));
output.print(" ");
}
}
ArrayList<Integer> array = new ArrayList<>();
try(
while (input.hasNext()) {
array.add(input.nextInt());
}
}
Collections.sort(array);
System.out.print(array);
System.out.println();
Page 9 of 9