
I want the answer for this question.
Question: Write a program to calculate and print the sum of odd numbers and the sum of even numbers for the first n natural numbers, where n is given as input from the user(using for loop).
Instructions: *You should surely use Functions in this question (That is an order from my teacher). :-( *BufferedReader should also be used as it is an input from the user. *For loop should be used.
Thank you! :-)

import java.io.*;
public class EvenOddExample{
public static int evenSum(int n){
int sum=0;
for(int i=1;i<=n;i++){
if(i%2==0){
sum+=i;
}
}
return sum;
}
public static int oddSum(int n){
int sum=0;
for(int i=1;i<=n;i++){
if(i%2!=0){
sum+=i;
}
}
return sum;
}
public static void main(String[]args)throws Exception{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Number: ");
int n=Integer.parseInt(br.readLine());
System.out.println("Sum of Odd Numbers between 1 and "+n+" are: "+oddSum(n));
System.out.println("Sum of Even Numbers between 1 and "+n+" are : "+evenSum(n));
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.