Java program to convert degree from centrigrade to fahrenheit

Posted on 2009-07-11
Last Modified: 2013-11-24
Program that displays a table of centrigrade temp 0 though 20 and their fahrnheit.  Program use a loop to display the table.

Problem, the program compiles with no errors. when I enter the degrees in centrigrade they convert and display in the fahrenheit field, however, when I enter the second degree, it appears on the same line as the previous. Not sure whether I am explaining this clearly.  If someone would compile the program, you'll see what I am talking about.

Thank you in advance for your assistance.
import java.util.Scanner; 

import javax.swing.JOptionPane;

public class CentrigradeGay


	public static void main (String[] args)


		final int BASE = 32; 

		final double CONVERSION_FACTOR = 9.0 / 5.0; 

		final int MIN_DEGREE = 0;

		final int MAX_DEGREE = 20;

		int degree;

		int number = 1;

		String input;


		Scanner keyboard = new Scanner(; 


		System.out.print("No more than 20 entries may be entered.");

		degree = keyboard.nextInt();



		if (degree > 0 && degree <= 20)	


			System.out.println("Please enter temperature" );




			System.out.println("Entries must be in the range of 0 and 20, please re-enter: ");

			degree = keyboard.nextInt();





			for (number = 1; number > 0 && number <= 20; number++)


					double centrigradeTemp; 


					centrigradeTemp = keyboard.nextDouble(); //read in user input

					double fahrenheitTemp;


					fahrenheitTemp = centrigradeTemp * CONVERSION_FACTOR + BASE; //calculate Fahrenheit temperature



						System.out.print("\t\t" + fahrenheitTemp);




Open in new window

Question by:gkilgore
LVL 23

Accepted Solution

Ajay-Singh earned 250 total points
Comment Utility
change this
 >> System.out.print("\t\t" + fahrenheitTemp);


System.out.println("\t\t" + fahrenheitTemp);

Assisted Solution

hrattan earned 250 total points
Comment Utility
try adding a \n


Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now