# Beginner question

barry richard

Greenhorn

Posts: 19

posted 3 years ago

///OUTPUT IS///

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

.....and so on.

Problem 1: No calculations are being done

Problem 2: Loop does not end at 20

I am running this on debian squeeze,

java version is

Thanks

- 0

///OUTPUT IS///

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

We have 3.75 liters

.....and so on.

Problem 1: No calculations are being done

Problem 2: Loop does not end at 20

I am running this on debian squeeze,

java version is

Thanks

Tina Raja

Greenhorn

Posts: 4

posted 3 years ago

- 0

I am quite new at JAVA however, I tried what you posted and it works for me - trying using this code

class Example{

public static void main(String [] args){

double gallons;

double liters;

int counter;

counter = 0;

for (gallons = 1; gallons <=20; gallons++){

liters = gallons * 3.75;

System.out.println("We have " + liters + " liters");

counter++;

if (counter == 5){

System.out.println();

counter = 0;

}

}

}

}

class Example{

public static void main(String [] args){

double gallons;

double liters;

int counter;

counter = 0;

for (gallons = 1; gallons <=20; gallons++){

liters = gallons * 3.75;

System.out.println("We have " + liters + " liters");

counter++;

if (counter == 5){

System.out.println();

counter = 0;

}

}

}

}

Tina Raja

Greenhorn

Posts: 4

posted 3 years ago

- 0

This is a common error. We even have a FAQ on it.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

posted 3 years ago

Tina, please edit your post and insert code tags properly.

- 0

Tina Raja wrote:I am quite new at JAVA however, I tried what you posted and it works for me - trying using this code

class Example{

public static void main(String [] args){

double gallons;

double liters;

int counter;

counter = 0;

for (gallons = 1; gallons <=20; gallons++){

liters = gallons * 3.75;

System.out.println("We have " + liters + " liters");

counter++;

if (counter == 5){

System.out.println();

counter = 0;

}

}

}

}

Tina, please edit your post and insert code tags properly.

OCPJP 6 86%

It is sorta covered in the JavaRanch Style Guide. |