/*
CSC110 Assignment:_Lab04.java__
Programmer: Phillip Sherman
Due Date: 2/13/12
Points: 35
Description of Application: Four methods (harmonic, sum, triangle, parellelogram)
Description of Inputs: Class constants N, SIZE, HEIGHT
Description of Outputs: '*', ' ', or intergers
*/
class Lab04 {
//Class constants required for modifying output of various methods
// N is used
public static final int N = 100;
public static final int SIZE = 3;
public static final int HEIGHT = 1;
public static void main
(String[] args
) {
harmonic();
sum();
triangle();
}
//Method for printing sum of harmonic series
public static void harmonic ()
{
//Declare Variable Double 'sum' to hold the harmonic series calculation
double sum=0;
for (int i=1; i<=N; i++) {
// i is used for Denominator of fraction (1/i)
// each run through loop adds the fraction to container 'sum'
sum += 1.0/i;
}
//printing Total value of 'sum' based upon CONSTANT N
System.
out.
println("Harmonic to " + N
+ " = " + sum
); }
//method for printing sum [Rules : Odd Integers up to N;
//sum of first N positive odd integers]
public static void sum ()
{
//Declare variables 'sum1' & 'sum2' for
//holding the sum amounts of the required calculations
//'sum 1' : Is for holding the computation of the sum of
// ODD integers up to N.
int sum1=0;
int sum2=0;
for (int i=1; i<=N; i+=2)
{
sum1 += i;
}
for (int j=1; j<=(N*2); j+=2)
{
sum2 += j;
}
System.
out.
println("Sum of odds UP to " + N
+ ": " + sum1
); System.
out.
println("Sum of first " + N
+ " odds : " + sum2
);
}
//method for printing a triangle of spaces & * using SIZE constant to
//format the output size
public static void triangle ()
{
//Declare variables to hold characters uses for
//creating desired shape
//Chosen to use variables in hopes of easier
//code to read
char star = '*';
char space = ' ';
for (int i=0; i<SIZE; i++)
{
for (int j=SIZE-i; j>=1; j--)
{
}
for (int k=1; k<=i; k++)
{
}
//Ends the line and
}
}
//method for printing a parallelogram of spaces & * using SIZE constant to
//format the output size
public static void parallelogram ()
{
}
//method for printing a diamond shape from '*' characters
//using HEIGHT constant to
public static void diamond ()
{
}
}