Hello Everybody,
I am learning Java from a few days.i am getting an error in one of my programs wherein i am trying to print thr sum of "n" numbers..the code is as follows..please help me
import java.math.*;
import java.util.*;
import java.io.*;
public class Add1{
public static void main(String args[]) {
int n;
System.out.println("eneter n");
Scanner keyboard=new Scanner(System.in);
/* n=JOptionPane.showInputDialog("enter a value");*/
int sum;
sum=0;
int i;
for(i=0;i<n;i++)
{
i=keyboard.nextInt();
sum=sum+i;
}
System.out.println("sum="+ sum);
}
}
i am getting the following error..
C:\Program Files\Java\jdk1.6.0_07\bin>javac Add1.java
Add1.java:18: variable n might not have been initialized
for(i=0;i<n;i++)
^
1 error
please help me...