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
Solved

Java program to convert degree from centrigrade to fahrenheit

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
wordcount challenge 11 132
micro services spring boot application error 3 236
tomcat administrtor 12 60
eclipse console opening separately 2 29
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 …
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.

839 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