Monday, May 19, 2008

I am working on a java program to determine if numbers in a series are odd or even. below is what i have so far

import java.util.Scanner;

public class EvenOdd
{
// determines whether numbers are even or odd
public void checkEvenOdd()
{
// create Scanner
Scanner input = new Scanner( System.in );
// obtain user input
System.out.print( "Enter three floating-point values seperated by spaces:" );
number = input.hasnext();

input = input;
}
while ( input.hasNext() )
{
int number = input.nextInt();

if ( isEven( number ) )
System.out.printf( "%d is even\n"- number );
else
System.out.printf( "%d is odd\n"- number );
} // end while loop
} // end method checkEvenOdd

// return true if number is even
public boolean isEven( int number )
{
return number % 2 == 0;
} // end method isEven
} // end class EvenOdd

I am working on program based on user input of radius to determine area- below is what I have so far. PLease make corrections on the below code.

import java.util.Scanner;
public class Circle
{
// calculate the areas of circles
public void calculateAreas()
{
//create scanner for input from command window
Scanner input = new Scanner ( System.in );

double radius = input.nextDouble(); // radius

// get the first radius
System.out.print( "Enter the radius (negative to quit): " );
double radius = input.nextDouble();

while ( radius >= 0 )
{

// call a procedure circleArea with a radius
circleArea( radius );

// get another radius

} // end while loop
} // end method calculateAreas

// calculate area
public void circleArea( double radius )
{
System.out.printf( "Area is %f\n"- Math.PI * radius * radius );
} // end method circleArea
} // end class Circle

No comments: