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; } }
2 Réponses
+ 5
What's the task?
+ 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) ?