0% found this document useful (0 votes)
4 views6 pages

Count Favorite Character in String

Uploaded by

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

Count Favorite Character in String

Uploaded by

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

count of fav char in string

-----------------------------
import [Link].*;
class HelloWorld {
public static void main(String[] args) {
Scanner S=new Scanner([Link]);
String s=[Link]();
int n=[Link]();
char c=[Link]().charAt(0);
int count=0;
for(int i=0;i<n;i++){
if([Link](i)==c){
count++;
}
}
[Link](count);
}
}
===================================================================================
==========
rebounced height
------------------
import [Link].*;
class HelloWorld {
public static void main(String[] args) {
Scanner S=new Scanner([Link]);
int H=[Link]();
int v=[Link]();
int vn=[Link]();
int en=v/vn;
int Hn=(int) (H*[Link](en,2));
[Link](Hn);
}
}
===================================================================================
====================
evenodd string
-------------------
import [Link].*;
class HelloWorld {
public static void main(String[] args) {
Scanner S=new Scanner([Link]);
int n=[Link]();
int[] a=new int[n];
for(int i=0;i<n;i++){
a[i]=[Link]();
}
String res="";
for(int i=0;i<n;i++){
if(a[i]%2==0){
res=res+"even";
}
else{
res=res+"odd";
}
}
[Link](res);
}
}
===================================================================================
=================
difference of sum and xor
-------------------------
import [Link].*;
class HelloWorld {
public static void main(String[] args) {
Scanner S=new Scanner([Link]);
int n=[Link]();
int[] a=new int[n];
for(int i=0;i<n;i++){
a[i]=[Link]();
}
int sum=0;
int xor=0;
for(int i=0;i<n;i++){
if(i%2!=0){
sum=sum+a[i];
}
else{
xor=xor^a[i];
}
}
[Link](sum-xor);
}
}
===================================================================================
===============
target sum
---------------------
import [Link].*;
class HelloWorld {
public static void main(String[] args) {
Scanner S=new Scanner([Link]);
int n=[Link]();
int[] a=new int[n];
for(int i=0;i<n;i++){
a[i]=[Link]();
}
int ans[]=new int[2];
int maxp=0;
for(int i=0;i<n;i++){
for(int j=0;j<n-1;j++)
{
if(a[i]+a[j]==18){
int t=a[i]*a[j];
if(t>maxp){
maxp=t;
ans[0]=a[i];
ans[1]=a[j];
}
}
}
}
[Link]([Link](ans));
}
}
import [Link].*;
class HelloWorld {
public static void main(String[] args) {
Scanner S = new Scanner([Link]);

// Input number of elements


int n = [Link]();
int[] a = new int[n];

// Input array elements


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

int[] ans = new int[2];


int maxp = 0;
Map<Integer, Integer> map = new HashMap<>();

// Single loop to find pairs that sum to 18 with the maximum product
for (int i = 0; i < n; i++) {
int complement = 18 - a[i];
if ([Link](complement)) {
int product = a[i] * complement;
if (product > maxp) {
maxp = product;
ans[0] = a[i];
ans[1] = complement;
}
}
[Link](a[i], i); // Add current element to the map
}

// Output result
if (maxp > 0) {
[Link]([Link](ans));
} else {
[Link]("No pair found with sum 18.");
}

[Link](); // Close scanner to avoid resource leaks


}
}

===================================================================================
=========================
fibinoce
--------
rt [Link].*;
class HelloWorld {
public static void main(String[] args) {
Scanner S=new Scanner([Link]);
int n=[Link]();
if(n==0|| n==1){
[Link]("1");
}
int[] f =new int[n+1];
f[0]=1;
f[1]=1;
for(int i=2;i<=n;i++){
f[i]=(f[i-1]*(i-1)+(i-2)*(i-2))%47;
}
[Link](f[n]);
}
}
===================================================================================
============
even sum
--------
import [Link].*;
class HelloWorld {
public static void main(String[] args) {
Scanner S=new Scanner([Link]);
int n=[Link]();
int[] a=new int[n];
for(int i=0;i<n;i++){
a[i]=[Link]();
}
int sum=0;
for(int i=n-1;i>=0;i--){
if(i%2==0){
sum=sum+a[i];
}
}
[Link](sum);
}
}
===================================================================================
===============
max sweets
--------------
import [Link].*;
class HelloWorld {
public static void main(String[] args) {
Scanner S=new Scanner([Link]);
int n=[Link]();
int e=[Link]();
int d=[Link]();
int ts=e*d;
int s=d/7;
int ed=d-s;
int mx=ed*n;
if(ts>mx)
{
[Link](-1);
}
int b=(ts+n-1)/n;
[Link](b);
}
}
=======================================================
no of candies he can buy
------------------------
import [Link].*;
class HelloWorld {
public static void main(String[] args) {
Scanner S=new Scanner([Link]);
int n=[Link]();
int[] a=new int[n];
for(int i=0;i<n;i++){
a[i]=[Link]();
}
int m=[Link]();
int c=0;
for(int i=0;i<n;i++){
if(a[i]%5==0){
c=c+1;
}
else{
if(a[i]<=m){
m=m-a[i];
c=c+1;
}
}
}

[Link](c);
}
}
============================================================
factor of 3
----------------
import [Link].*;

class HelloWorld {
public static void main(String[] args) {
Scanner S = new Scanner([Link]);
int n=[Link]();
int[] a=new int[n];
for(int i=0;i<n;i++){
a[i]=[Link]();
}
int c=0;
for(int i=0;i<n;i++){
if(a[i]%3==0){
c++;
}
}
[Link](c);
}
}

using functions
----------------
import [Link].*;

class HelloWorld {
public static int mul(int[] a,int n){
int c=0;
for(int i=0;i<n;i++){
if(a[i]%3==0){
c++;
}
}
return c;
}
public static void main(String[] args) {
Scanner S = new Scanner([Link]);
int n=[Link]();
int[] a=new int[n];
for(int i=0;i<n;i++){
a[i]=[Link]();
}
int ans=mul(a,n);
[Link](ans);
}
}

==================================================================
import [Link].*;

class HelloWorld {
public static void main(String[] args) {
Scanner S = new Scanner([Link]);
int n = [Link]();
String s = "";
while (n > 0) {
int digit = n % 10;
s = digit + s;
n = n / 10;
}

StringBuilder Str = new StringBuilder();


for (int i = 0; i < [Link](); i++) {
char cu = [Link](i);
if (cu == '0') {
[Link]('5');
} else {
[Link](cu);
}
}

int num = [Link]([Link]());


[Link](num);
}
}

You might also like