Grading Students HackerRank solution
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static int[] solve(int[] grades){
int arr[]=new int[grades.length];
for(int i=0;i<grades.length;i++){
if((grades[i]%5==0)){
arr[i]=grades[i];
}
else{
for(int j=grades[i]+1;j<=grades[i]+2;j++){
if(j%5==0){
if(j<40){
arr[i]=grades[i];
}
else{
arr[i]=j;
break;
}
}
else{
arr[i]=grades[i];
}
}
}
}
return arr;
// Complete this function
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] grades = new int[n];
for(int grades_i=0; grades_i < n; grades_i++){
grades[grades_i] = in.nextInt();
}
int[] result = solve(grades);
for (int i = 0; i < result.length; i++) {
System.out.print(result[i] + (i != result.length - 1 ? "\n" : ""));
}
System.out.println("");
}
}
Hie guys this is me, Jaideep
This is my first Blog. I am tech enthusiastic person i do coding Practice and here is my first code post
This is my first Blog. I am tech enthusiastic person i do coding Practice and here is my first code post
Comments
Post a Comment