Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Java program to convert degree from centrigrade to fahrenheit

Posted on 2009-07-11
2
Medium Priority
?
468 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 1000 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 1000 total points
ID: 24831578
try adding a \n

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

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.

636 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