Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Odd sum loop

807600Oct 30 2007 — edited Oct 30 2007
I need to create an application that prompts for a number and then sums all odd numbers from 1 to the entered number.
public class OddSum {
	public static void main (String[] args) {
		int num;	// input number
		int OddSum;	// Sum of odd numbers

		Scanner input = new Scanner(System.in);
		System.out.print("Enter a limit number: ");
		num = input.nextInt(); 
		for (int i=0; i<= num; i++)
			System.out.println (" Sum of all Odd numbers within the limit is: ");
		}}
I made that kinda as a skeleton but i dont know how to finish the code or how to use "for" correctly.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 27 2007
Added on Oct 30 2007
33 comments
432 views