Machine Problem
Write a program using Java to ask the user to give a number and then the program will sum all the odd and even numbers of the given number, and display the results on the screen.
I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
/* Odd_Even.java
*
* Prof. Jake Roderiguez Pomperada, MAED-IT, MIT
* www.jakerpomperada.com and www.jakerpomperada.blogspot.com
* jakerpomperada@gmail.com
* Bacolod City, Negros Occidental Philippines
*
*
Machine Problem
Write a program using Java to ask the user to give a number
and then the program will sum all the odd and even numbers of
the given number, and display the results on the screen.
*/
import java.util.Scanner;
class Odd_Even
{
public static void main(String args[])
{
int a=0,num=0;
int odd_numbers_sum=0,even_numbers_sum=0;
Scanner input = new Scanner(System.in);
System.out.println("\n");
System.out.println("\tSum of All Odd and Even Numbers in Java");
System.out.println();
System.out.print("\tGive a Number : ");
num=input.nextInt();
for(a=1; a<=num; a++){
if(a%2==0)
even_numbers_sum=even_numbers_sum+a;
else
odd_numbers_sum=odd_numbers_sum+a;
}
System.out.println("\n");
System.out.println("\tSum of all odd numbers are: "+odd_numbers_sum);
System.out.println("\tSum of all even numbers are: "+even_numbers_sum);
System.out.println("\n");
System.out.println("\tEnd of Progam");
System.out.println();
}
}
/* Odd_Even.java * * Prof. Jake Roderiguez Pomperada, MAED-IT, MIT * www.jakerpomperada.com and www.jakerpomperada.blogspot.com * jakerpomperada@gmail.com * Bacolod City, Negros Occidental Philippines * * Machine Problem
Write a program using Java to ask the user to give a number and then the program will sum all the odd and even numbers ofthe given number, and display the results on the screen. */
import java.util.Scanner;
class Odd_Even
{ public static void main(String args[])
{
int a=0,num=0; int odd_numbers_sum=0,even_numbers_sum=0; Scanner input = new Scanner(System.in);
System.out.println("\n"); System.out.println("\tSum of All Odd and Even Numbers in Java"); System.out.println(); System.out.print("\tGive a Number : "); num=input.nextInt();
for(a=1; a<=num; a++){ if(a%2==0) even_numbers_sum=even_numbers_sum+a; else odd_numbers_sum=odd_numbers_sum+a; } System.out.println("\n"); System.out.println("\tSum of all odd numbers are: "+odd_numbers_sum); System.out.println("\tSum of all even numbers are: "+even_numbers_sum); System.out.println("\n"); System.out.println("\tEnd of Progam"); System.out.println(); }
}
No comments:
Post a Comment