Accen Codes
Accen Codes
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String input1 =sc.nextLine();
int input2=sc.nextInt();
String input3= sc.next();
int result = countCharacter(input1,input2,input3);
System.out.println(result);
}
public static int countCharacter(String input1,int input2,String input3){
if(input2 > input1.length()){
input2=input1.length();
}
String subString = input1.substring(0,input2);
char targetChar = input3.charAt(0);
int count=0;
for(char ch:subString.toCharArray()){
if(ch == targetChar){
count++;
}
}
return count;
}
}
// Final check after the loop in case the longest streak is at the end
if (currentStreak >= 3) {
longestStreak = Math.max(longestStreak, currentStreak);
}
return longestStreak;
}
// Output result
System.out.println(longestDropPeriod(input1, input2)); // Expected output: 4
}
}
3)VOWEL PERMUTATION:
import java.util.*;
public class VowelPermutation {
public static int vowelPermutation(String input1) {
int consonants = 0;
for (char ch : input1.toLowerCase().toCharArray()) {
if ("aeiou".indexOf(ch) == -1 && Character.isLetter(ch)) {
consonants++;
}
}
if (consonants == 0) {
return 0;
}
return factorial(consonants);
}
private static int factorial(int n) {
if (n <= 1) {
return 1;
}
return n * factorial(n - 1);
}
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
String input1 = sc.nextLine();
System.out.println(vowelPermutation(input1));
}
}
5) REBOUND HEIGHT:
import java.util.Scanner;
public class Solution {
public static int rebound(int input1, int input2, int input3) {
double e = (double) input3 / input2;
double reboundHeight = input1 * Math.pow(e, 2);
return (int) reboundHeight;
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int input1 = scanner.nextInt();
int input2 = scanner.nextInt();
int input3 = scanner.nextInt();
int result = rebound(input1,input2,input3);
System.out.println(result);
scanner.close();
}
}
Output:
Enter initial height (H): 100
Enter initial velocity (V): 20
Enter final velocity (Vf): 10
The rebound height after N bounces is: 25
import java.util.Scanner;
int curr = 0;
int i = 0;
return res;
}
sc.close();
}
}
Output:
stone
5
bone clone phone tone zone
Tone
7)ISLAND LIFE:
import java.util.Scanner;
// Check if the number of sweets required is more than what can be bought
if (totalSweets > buyDays * input1) {
return -1;
}
int minBoxes = (int) Math.ceil((double) totalSweets / input1);
return minBoxes;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int input1 = sc.nextInt();
int input2 = sc.nextInt();
int input3 = sc.nextInt();
int result = minimumBoxes(input1, input2, input3);
System.out.println(result);
}
}
Output:
10
2
7
2
8) NAME ENTRY:
import java.util.Scanner;
public class NameFormatter {
public static String formatName(String input1, String input2) {
// Convert first name to lowercase and last name to uppercase
String formattedFirstName = input1.toLowerCase();
String formattedLastName = input2.toUpperCase();
// Return the formatted name
return formattedFirstName + " " + formattedLastName;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter first name: ");
String input1 = sc.nextLine();
System.out.print("Enter last name: ");
String input2 = sc.nextLine();
// Call the formatName function and print the result
String result = formatName(input1, input2);
System.out.println("Formatted Name: " + result);
}
}
Output:
Enter first name: VIRat
Enter last name: koHLi
Formatted Name: virat KOHLI
9) FIND DIVIDEND:
public class Main {
public static int findDividendIndex(int[] array, int divisor, int quotient, int
remainder, int length) {
int dividend = divisor * quotient + remainder;
return searchDividendIndex(array, dividend, length);
}
private static int searchDividendIndex(int[] array, int dividend, int length) {
for (int i = 0; i < length; i++) {
if (array[i] == dividend) {
return i;
}
}
return -1;
}
public static void main(String[] args) {
int[] array = {10, 15, 20, 25, 30};
int divisor = 5;
int quotient = 3;
int remainder = 0;
int length = array.length;
int index = findDividendIndex(array, divisor, quotient, remainder, length);
System.out.println("Index of dividend: " + index);
}
}
Output:
Enter string A: ABCDEF
Enter string B: BDF
Result: ACE
import java.util.Scanner;
public class ReverseArray {
public static int sumEvenPositions(int[] input1, int input2) {
int sum = 0;
for (int i = 0; i < input2 / 2; i++) {
int temp = input1[i];
input1[i] = input1[input2 - i - 1];
input1[input2 - i - 1] = temp;
}
for (int i = 0; i < input2; i += 2) {
sum += input1[i];
}
return sum;
}
public static void main(String[] args) {
int[] input1 = {10, 20, 30, 40, 50, 60};
int input2 = 6;
// Expected Output: Sum of elements at even positions in reversed array
int result = sumEvenPositions(input1, input2);
System.out.println(result);
}
}
OUTPUT : 120
OUTPUT: (9,9)
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
int input1 = sc.nextInt();
int shadowArea = calculateCanopyShadowArea(input1);
System.out.println(shadowArea);
}
public static int calculateCanopyShadowArea(int input1) {
double pi = 3.141;
double area = pi * input1 * input1;
//return (int) Math.round(area);
return (int)area;
}
}
Output:
5
78