Sharp Tutorial
sum and average of even and odd numbers using command line

Python

Java

C

C++

HTML/CSS

Java Script

PHP

SQL

C Programs

Week 1

  • Ans of Question 1
  • Ans of Question 2
  • Ans of Question 3
  • Ans of Question 4
  • Ans of Question 5

Week 2

  • Ans of Question 1
  • Ans of Question 2
  • Ans of Question 3
  • Ans of Question 4
  • Ans of Question 5

Week 3

  • Question 1
  • Question 2
  • Question 3
  • Question 4
  • Question 5

Week 4

  • Question 1
  • Question 2
  • Question 3
  • Question 4
  • Question 5

Week 5

  • Question 1
  • Question 2
  • Question 3
  • Question 4
  • Question 5

Solution of java assignment questions

Even Odd sum and average program using command line

class EvenOddSumAvg
{
	public static void main(String args[])
	{
		int evensum=0,oddsum=0,evenavg=0,oddavg=0,evencount=0,oddcount=0;
		for(int i=0; i<args.length; i++)
		{
		int n=Integer.parseInt(args[i]);	
		if(n%2==0)
		{
		evensum=evensum+n;
		evencount++;
		}
		else
		{
		 oddsum=oddsum+n;
		 oddcount++;
		}
		}
           evenavg=evensum/evencount;
           oddavg=oddsum/oddcount;   
          System.out.println("the sum of even numbers is "+evensum+" average of even numbers "+evenavg);
	  System.out.println("the sum of odd numbers is "+oddsum+" average of odd numbers "+oddavg);

    }

}

}
 

Enquiry about Course

Ask your Question

Watch video in full size

Video tutorial

Click To Read: SQL Tutorial With Easy Example Queries.

Follow by Email
Facebook
Facebook
fb-share-icon
YouTube
Copyright © Sharp Tutorial
Build with WordPress
Wordpress Social Share Plugin powered by Ultimatelysocial
Sharp Tutorial