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

A1

Uploaded by

varshini
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)
11 views3 pages

A1

Uploaded by

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

import java.io.

*;

/*class Accenture{
public static double stddev(int[] arr){
//formula=>s.d=sqrt(((arr[1]-A)^2+(arr[2]-A)^2+....../N)
//step 1=> cal avg value
int n = arr.length;
double avg=0;
for(int i=0;i<n;i++){
avg+=arr[i];
}
//step 2=>calculate sum of sqs
double sumofsq=0;
for(int i=0;i<n;i++){
sumofsq+=Math.pow((arr[i]-avg),2);
}
//step 3=>cal variance (sd)
double variance=sumofsq/n;
return Math.sqrt(variance);
}
public static void main(String[] args){
Accenture acc = new Accenture();
int[] sdarr={3,8,4,2,5,6,7 };
double result=acc.stddev(sdarr);
System.out.println(result);
}
}*/

/*class Accenture{
public static int calcards(int n){
//partialval=(3*1)+(3*2) => partialvalue-n

int ans = 0;
for(int i=0;i<= n;i++){
ans+=i*3;
}
int finalans=ans-n;
return finalans;
}
public static void main(String[] args){
Accenture acc =new Accenture();
int nooflevels=3;
double result=acc.calcards(nooflevels);
System.out.println(result);
}
}*/

/*
public class Accenture{
public static int xor(int a, int b){
return a^b;
}
public static int or(int a, int b){
return a|b;
}
public static int and(int a, int b){
return a&b;
}
//input "1C0B1A1" A=>and ,B=>or ,C=>xor
public static int calculateBinaryOp(String str){
int ans =0;//initial
//1st logic =>if charAt(1)==c =>call xor(charAt(0),charat(1)) or B or A
if(str.charAt(1)=='C'){

ans=xor(Character.getNumericValue(str.charAt(0)),Character.getNumericValue(str.char
At(2)));//1
}else if(str.charAt(1)=='B'){

ans=or(Character.getNumericValue(str.charAt(0)),Character.getNumericValue(str.charA
t(2)));
}else{

ans=and(Character.getNumericValue(str.charAt(0)),Character.getNumericValue(str.char
At(2)));
}
//ans=1
//2nd logic
for(int i=3;i<str.length();i+=2){//"B1A1"
if(str.charAt(i)=='C'){//xor
ans= xor(ans,Character.getNumericValue(str.charAt(i+1)));
}else if(str.charAt(i)=='B'){
ans= or(ans,Character.getNumericValue(str.charAt(i+1)));

}else{
ans= and(ans,Character.getNumericValue(str.charAt(i+1)));
}
}
return ans;
}
public static void main(String[] args){
Accenture acc = new Accenture();
String string = "1C0B1A1";
System.out.println(acc.calculateBinaryOp(string));
}
}*/

//coding ques no 4
//0:0,1:1....9:9,10:A,11:B....35:Z)
// import java.util.HashMap;
//n=12 ,num=718
public class Accenture{
public static String decttoNBase(int n,int number){
StringBuilder ans = new StringBuilder();
HashMap<Integer,String> d = new HashMap<>();

//map for digits


for(int i=1;i<10;i++){
d.put(i,String.valueOf(i));//String.valueOf is used to convert non string
values to the string values
}

//map for Alphablets


char letter ='A';
for(int i=10;i<36;i++){
d.put(i,String.valueOf(letter));
++letter;
}

//convert number to base n


int remainder = number%n;//225/16 => remainder=10(A)
number/=n;//number=number/n 225/16 =>quotient =59 number=59

ans.append(d.get(remainder));//A

while(remainder>0){
remainder=number%n;
number/=n;
if(remainder==0){
break;
}
ans.append(d.get(remainder));
}

//reverse the result


return ans.reverse().toString();
}
public static void main(String[] args){
int n=12;
int number =718;
String finalResult = decttoNBase(n,number);
System.out.println(finalResult);
}
}

You might also like