Reputation:
I am new to this site and new to programming I just started a week a go. I've been tasked with making a conversion table from degrees Fahrenheit to Celsius. the table needs to start at 0 Celsius and stop at 100 degrees Celsius and go by increments of 5.
I am really trying to make it work but I can't seem to get the for loop
working correctly. Can someone explain to me what I am doing wrong and how I can finish this program to work the way I need it?
public class Table
{
public static void main(String[] args)
{
System.out.println("Conversion Table");
final int TOTAL = 100;
for (int c = 0; c <= TOTAL; c+=5)
{
System.out.println((c*9/5)+32 +"\t");
{
System.out.println();
}
}
}
Upvotes: 2
Views: 2815
Reputation: 109
1-You have one less closing brace. 2-For making conversion table you have to show both Fahrenheit and Celsius value. Code for this would be.
public class A
{
public static void main(String[] args)
{
System.out.println("Conversion Table");
final int TOTAL = 100;
System.out.println("Fahrenheit"+"\t Celsius");
for (int c = 0; c <= TOTAL; c+=5)
{
System.out.println((c*9/5)+32 +"\t \t" + c);
{
System.out.println();
}
}
}
}
Upvotes: 0
Reputation: 371
Currently you are only printing the values of the Fahrenheit to standard out. If the idea is that you want to print to standard out the table then you probably want to add the Celsius value as well. Add something like
System.out.println(c + "\t" + ((c*9/5)+32) +"\t");
to your output and you'll be sweet.
Upvotes: 2