Solved

Java program to convert degree from centrigrade to fahrenheit

Posted on 2009-07-11
2
466 Views
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.in); 
	
		System.out.print("No more than 20 entries may be entered.");
		degree = keyboard.nextInt();
		System.out.println();
			
		if (degree > 0 && degree <= 20)	
			{	
			System.out.println("Please enter temperature" );
			}
		else
			{	
			System.out.println("Entries must be in the range of 0 and 20, please re-enter: ");
			degree = keyboard.nextInt();
			}
 
			System.out.println("Centrigrade\t\tFahrenheit");
			System.out.println("============================");
	
			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(centrigradeTemp);
						System.out.print("\t\t" + fahrenheitTemp);
				}	
	}
}

Open in new window

0
Comment
Question by:gkilgore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
Ajay-Singh earned 250 total points
ID: 24831577
change this
 >> System.out.print("\t\t" + fahrenheitTemp);

to

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

Assisted Solution

by:hrattan
hrattan earned 250 total points
ID: 24831578
try adding a \n

System.out.println("============================\n");
       
0

Featured Post

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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.

717 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