Solved

Java program to convert degree from centrigrade to fahrenheit

Posted on 2009-07-11
2
465 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mapAB Challlenge 35 174
Non-recursive backtracking, using a stack 1 248
jboss wildfly 10.1 10 437
batch vs regular insert in spring DAO 2 25
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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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.

726 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