0

Why last test case not pass??

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n =sc.nextInt(); int ans =re(n); if(n>8){ System.out.println(ans); }else{ System.out.println(-1); } } static int re(int n){ if(n==3){ return 3; } int result=0; for(int i =1;i<n;i++){ if(i%3==0||i%5==0){ result = result+i; } } return result; } }

6th Sep 2023, 3:12 AM
DevjiCoder
DevjiCoder - avatar
2 ответов
+ 5
What's the task?
6th Sep 2023, 6:35 AM
Ausgrindtube
Ausgrindtube - avatar
+ 1
Hi, in your re method N will never return 3 if you enter that number because your if statement in your main method is checking if your input is higher than 8. You sure you not mean if(n<8) instead of if(n>8) ?
7th Sep 2023, 5:25 PM
JavaBobbo
JavaBobbo - avatar