- Get link
- X
- Other Apps
Output : 4 // instead of 3
YouTube Link : Click Here
package Accenture_Coding_Question;
import java.util.*;
public class Square_Plot {
public static void main(String[] args) {
int n =6;
int arr[] = {64,38,16,81,50,100};
int count = 0;
for(int i=0;i<n;i++) {
// int ans = (int)Math.sqrt(arr[i]) * (int)Math.sqrt(arr[i]);
//if(ans == arr[i]){
// count++;
//}
double sqare = Math.sqrt(arr[i]);
if(Math.ceil(sqare) == Math.floor(sqare)){
count++;
}
}
System.out.print(count);
}
}
package Accenture_Coding_Question;
public class Find_Max_Value {
public static void main(String[] args) {
int arr[] = {1,5,4,8,9,2,3};
int maxNum = Integer.MIN_VALUE;
int idx = 0;
for(int i=0;i<arr.length;i++){
if(maxNum < arr[i]){
maxNum = arr[i];
idx = i;
}
}
System.out.print(maxNum + "\n" + idx );
}
}
package Accenture_Coding_Question;
public class No_Of_Bricks_To_Make_House {
public static void main(String[] args) {
int houseLevel = 3;
if(houseLevel == 0){
return;
}
int bricks = 2;
int ans = bricks;
for(int i=2;i<=houseLevel;i++){
bricks +=3;
ans += bricks;
}
System.out.println(ans);
}
}
OR
package Accenture_Coding_Question;
public class No_Of_Bricks_To_Make_House {
public static void main(String[] args) {
int houseLevel = 3;
if(houseLevel == 0){
return;
}
int bricks = 2;
int ans = bricks;
for(int i=0;i<= houseLevel;i++){
bricks = (houseLevel*(3*houseLevel + 1))/2; // Changed Line
}
System.out.println(bricks);
}
}
Comments
Post a Comment