TOPIC
5% wrong answer help me
supermanshuvo asked 4 years ago
when I test the code in my compiler it show me the right answer. Why in here i got 5% wrong ansere? please someone help me...
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); int X = in.nextInt(); int Y = in.nextInt(); if(X<0 && Y<0){ X = Math.abs(X); Y = Math.abs(Y); }else if(X<0){ X = Math.abs(X); }else if(Y<0){ Y = Math.abs(Y); } if(X>Y){ int temp = X; X = Y; Y = temp; } int sum = 0; for(int i = X;i<Y;i++){ if(i%2==1){ sum+=i; } } System.out.println(sum); } }