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

A2

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)
4 views2 pages

A2

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/ 2

import java.io.

*;
import java.util.*;
//coding ques = 5
//frunction to find the roots of quadratic eqn => ax^2+bx+c=0
//formula x1=-b+sqrt(b^2-4ac)/2a x2=-b-sqrt(b^2-4ac)/2a
//eg => i/p =>input 1 :1, input 2 :2, input 3 :3 o/p=>{3.0,-1.0}
/*
public class Accentureb{
public static List<Double> calculateRoots(double a,double b,double c){
List<Double> roots = new ArrayList<>();

double root1 = -b+Math.sqrt(b*b-4*a*c)/2*a;


double root2 = -b-Math.sqrt(b*b-4*a*c)/2*a;

roots.add(root1);
roots.add(root2);

return roots;
}
public static void main(String[] args){
double a=1.0;
double b=-3.0;
double c =2.0;

List<Double> result = calculateRoots(a,b,c);


// System.out.println(result.get(0)+","+result.get(1));
System.out.println(result);
}
}
*/

// coding ques 6
// Sum of the largest num and smallest number in array
//eg=> arr={1,2,3,5,1,2} => L=5 S=1 o/p => 5+1=6
/*class Accentureb{
public static int sumOfLargestAndSmallest(int[] arr){

int min=arr[0];
int max=arr[0];

for(int i=0;i<arr.length;i++){
if(arr[i]<min){//initial 1
min = arr[i];
}
if(arr[i]>max){
max=arr[i];
}
}

return min+max;
}
public static void main(String[] args){
int arr[] = {1,2,3,5,1,2};
int result = sumOfLargestAndSmallest(arr);
System.out.println(result);
}
}
*/
// coding ques => 7
//find Autobiographic number =>1210 if yes =>find distinct numbers => o/p=>1,2,3 =>
3
//write a func autoCount(String n)
/*
public class Accentureb{

public static boolean isAutobiographicNum(String n){//n="1210" to check


autobio num
//1210,1
for(int i=0;i<n.length();i++){//1210
System.out.println("string
"+countOccurences(n,String.valueOf(i)));

if(countOccurences(n,String.valueOf(i))!
=Character.getNumericValue(n.charAt(i))){
return false;
}
}
return true;
}

public static int autoCount(String n){//main final result function


if(n.length()==0){
return 0;
}
if(isAutobiographicNum(n)){
return countUniqueDigits(n);
}
else{
return 0;
}
}
//str =1210 ,target=1 =>4-2=2 target 1=2
//str =1210 ,target=2 =>4-1=3
public static int countOccurences(String str,String target){
return str.length()-str.replace(target,"").length();
}

public static int countUniqueDigits(String str){//count distinct digits


return (int)str.chars().distinct().count();
}

public static void main(String[] args){


System.out.println(autoCount("1210"));

}
}
*/

You might also like