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.