program in java to sum 5 odd number
Answers
Answered by
1
Answer:
public calss OddNumbers
{
public static void main(String args[])
int a=1, b=3, c=5, d=7, e=9, s=0;
s=a+b+c+d+e
System.out.println("Sum=" +s);
}
Answered by
0
// Java Program to Calculate Sum of Odd Numbers using for loop
import java.util.Scanner;
public class SumofOdd1 {
private static Scanner sc;
public static void main(String[] args)
{
int number, i, oddSum = 0;
sc = new Scanner(System.in);
System.out.print(" Please Enter any Number : ");
number = sc.nextInt();
for(i = 1; i <= number; i++)
{
if(i % 2 != 0)
{
oddSum = oddSum + i;
}
}
System.out.println("\n The Sum of Odd Numbers upto " + number + " = " + oddSum);
}
}
————————————————————
If helpful pls mark as brainliest
CHEERS
@OOOIRKIOOO
import java.util.Scanner;
public class SumofOdd1 {
private static Scanner sc;
public static void main(String[] args)
{
int number, i, oddSum = 0;
sc = new Scanner(System.in);
System.out.print(" Please Enter any Number : ");
number = sc.nextInt();
for(i = 1; i <= number; i++)
{
if(i % 2 != 0)
{
oddSum = oddSum + i;
}
}
System.out.println("\n The Sum of Odd Numbers upto " + number + " = " + oddSum);
}
}
————————————————————
If helpful pls mark as brainliest
CHEERS
@OOOIRKIOOO
Similar questions