Re: coding error-please help
You are not saying what type of errors you are receiving but are you sure you have imported the Scanner object from java.util?
Code:
import java.util.Scanner;
This is essential to make the code run. What IDE are you using?
Here is working code:
Code:
import java.util.Scanner;
class AddUpIntegers{
public static void main (String[] args ){
Scanner scan = new Scanner( System.in );
int N, sumAll = 0, sumEven = 0, sumOdd = 0;
System.out.print( "Enter limit value: " );
N = scan.nextInt();
int count = 1;
while ( count <= N ){
sumAll = sumAll + count ;
if ( count % 2 == 0 )
sumEven = sumEven + count ;
else
sumOdd = sumOdd + count;
count = count + 1 ;
}
System.out.print ( "Sum of all : " + sumAll );
System.out.print ( "\tSum of even: " + sumEven );
System.out.println( "\tSum of odd : " + sumOdd );
}
}
Re: coding error-please help
Thanks, Zyr. That worked. I can't believe I didn't get that part. Lesson learned.
Re: coding error-please help
You are saying you get red "carrots" below your code, signaling to you that there is something wrong with it. What program are you coding in? Eclipse or Netbeans will tell you what is wrong with the code, and also suggest solutions to make the code compile. If you are not using one of these programs, I suggest you look into it.
One can always argue that writing code in Notepad is a better way to go since you have to learn more stuff the hard way, but I for one have progressed my learning so much faster by getting the built in help from Eclipse.