Program Converting Fahrenheit To Celsius Using For Loop (will Not Convert)
Sep 13, 2014
I am trying to write a program converting Fahrenheit to Celsius using a for loop. I get it to run and Fahrenheit goes to a hundred. My issue is that the Celsius just says 100 down the column and is not converting. I have tried messing with it, and can not figure what is wrong with it.
import java.util.Scanner;
public class Controlstatement {
public static void main(String[] args) {
double F = 1.0;
double Celcius = 100;
System.out.printf("%s%20s
", "Farenheit", "Celcius" );
for (int Farenheit = 0; Farenheit <= 100; Farenheit++) {
F = Celcius * (Farenheit - 32 * 5.0/9.0);
System.out.printf("%4d%,20.2f
", Farenheit, Celcius);
}
}
}
I need to do a conversion of Celsius to Fahrenheit and viceversa using methods and a for loop. The methods are public static double celsiustoFahrenheit (double celsius) and public static double Fahrenheittocelsius (double fahrenheit). It gives me weird numbers and i have to have some format that you can see attached ....
package temperatureconverter; import java.util.Scanner; public class TemperatureConverter { public static void main(String[] args) { Scanner corvette = new Scanner(System.in); System.out.printf("%12s%12s","Celsius","Fahrenheit");
I'm new to coding and we have an assignment for class to convert fahrenheit to celsius so far this is what i have:
import java.util.Scanner; public class Lab5 { public static void main(String[] args) { //variable dec Scanner scan = new Scanner(System.in); double input;
[code]...
This is what he wants us to do "Write a method name celsius that accepts a Fahrenheit temperature as an argument. The method should return the temperature, converted to Celsius. Demonstrate the method by asking the user a temperature value to convert. Then below the result, call a loop that displays a table of the Fahrenheit temperatures 0 through 20 and their Celsius equivalents."
I’m trying to write a program in Java that will take the input of a temperature in Fahrenheit and convert it to Celsius and Kelvin. This is what I have so far but when I run the program on Eclipse it says the temp. in Celsius is infinity and the same for kelvin. Why is it not preforming the operation and spiting out the correct numbers?
import java.util.Scanner; public class Temperature { public static void main(String[] args) { // This program converts temperatures from Fahrenheit to Celsius to Kelvin. double temperature1;// operands double temperature2; double temperature3;
Write java program using table that stores celsius and farenheit values that are equal to one another using a loop. use C 0-20 and convert to farenheit.
I have to use doubles for Celsius and Fahrenheit and in the formula. I get a runtime error with the following displayed:
I will display a table of temperatures in their Celsius and Farenheit equivalents.
celsiusfarenheit
import java.util.*; import java.lang.*; import java.io.*; class TemperatureConversion { public static void main (String[] args) throws java.lang.Exception { double celsius;// Temperature in degrees Celsius minimum double farenheit;// Temperature in degrees Fahrenheit
I've made a simple program in Java (Eclipse) that converts Fahrenheit to Celsius.The class is:
Java Code: package ehu.student; public class ConversorTemperaturas { /*--------------------------------------------------------------*/ /*Clase que dado una temperatura en Fahrenheit la canvierte en C*/ /*--------------------------------------------------------------*/ public float farenheit2celsius (float d){ float celsius, aux;
[code]...
When I write t.farenheit2celsius(25.6), appears the following error: "The method farenheit2celsisus(float) in the type ConversorTemperaturas is not applicable for the arguments (double)"If i change in the class the type float for double there is not problem. Why can't i use the type float?
I was asked to work on building a program that can convert Fahrenheit to kelvin. Need to create a for loop that spits out the value of kelvin for every degree increase from 32 degrees Fahrenheit to 100 degrees Fahrenheit.
Write a CiUI application that converts Celsius temperatures to Fahrenheit temperatures. The user should be able to enter a Celsius temperature, click a button, and then sec the equivalent Flhnfflhelt temperature. Use the following formula to make the conversion: F - - y C + 32..F is the Fahrenheit temperature and C is the Celsius temperature.
Now the program runs (In Jgrasp) But when I Enter a number in the fahrenheit box and hit "COnvert' NOTHING happens. I went over my code and I can't find what seems to be the problem...I tried changing
ActionListener Listener = new ConvertListener(); convertBtn.addActionListener(ConvertListener); <----- I tried changing ConvertListener to just Listener but it gives me more problems import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField;
I am new to java and I am trying to learn a little about GUI. I found this problem of creating a converter for temp from farenheit to celcius. I have everything working, except for when I hit the converter button... it does not convert.
The assignment reads: Develop a Java program (F2C.java) for converting a temperature from the Fahrenheit to the Celsius scale. The program will read the temperature graphically using an input dialog box
(JOptionPane.showInputDialog) and will show also the result graphically on a message dialog box (JOptionPane.showMessageDialog).
I can get my input box to show, but I am unable to get to the output box
What I have came up with:
import javax.swing.JOptionPane; public class F2C { public static void main(String[] args) { // Enter Farenheit String Fahrenheit = JOptionPane.showInputDialog(
I have followed the instructions carefully but the conversion values are not correct.
Write a program that displays a table of the Celsius temperatures 0 through 20 and their Fahrenheit equivalents. The formula for converting a temperature from Celsius to Fahrenheit is F - | C + 32 where ¥ is the Fahrenheit temperature and C is the Celsius temperature. Your program must use a loop to display the table.
Code
public class TempConversion { public static void main(String[] args) { for(double i = 0; i <= 20.0; i++) {
I am new to Java, programming, and intelliJ. I am trying to make a BMI Calculator using this code as my initial template which converts Fahrenheit to Celsius.
import javax.swing.JFrame; public class Fahrenheit { //----------------------------------------------------------------- // Creates and displays the temperature converter GUI. //-----------------------------------------------------------------
[code]....
I created a local field within BMIButtonListener for weight, height, resultLabel, and was able to compile but it did not calculate and listed exceptions.
<import javax.swing.JOptionPane; public class TempCalc {
public static void main(String[] args) {
//Confirming which conversion to compute. String FarOrCel = (JOptionPane.showInputDialog("Would you like to calculate a Farenheit value or a Celsius value? (Enter Farenheit or Celsius)");
[Code] ....
So I've been trying to come up with a Farenheit to Celsius converter and back. However, whenever I run the program in JCreator it never recognizes the string "Farenheit". Even if I put that exact thing (I copy/pasted from the if (FarOrCel == "Farenheit")) it keeps asking me for a Celsius value.
[quote name='INNOCENTREAPER##!' date='28 September 2014 - 07:40 PM' timestamp='1411958437' post='2057072']
<import javax.swing.JOptionPane; public class TempCalc { public static void main(String[] args) {
//Confirming which conversion to compute. String FarOrCel = JOptionPane.showInputDialog("Would you like to calculate a Farenheit value or a Celsius value? (Enter Farenheit or Celsius)";
How to convert this program from a while loop to a for loop.
import java.util.Scanner; public class LongDivision { public static void main(String arguments[]){ Scanner input = new Scanner(System.in); System.out.println("Enter the dividend: ");
Technically, when you run the program, a gif page appears (that I put as a placeholder) and when you press the letter 'n' JCreator runs the program, displaying a character P on a .txt field made using the Notepad on Windows. You can move it left, right, down, and up andf it will move accordinly. However, each time I make such action, the compiler has to rewrite to whole .txt field with the new position.
My former tutor said that in order for it to be "real-time", we have to use an applet.
The idea behind this program is that the program prompts the user to input an initial base (2-36), which checks to ensure that it is a valid int, then asks for a number to convert (which is taken as a String), then it asks which desired base the user would like to convert said number to. I have a basic program that is not complete, but allows me to do a few conversions using convertTo. I believe that I am going to have abandon this method and try mathematically converting every number. This leads me to what I can and cannot do. I am unable to use the initialBase as a condition to know what kind of number i an converting. For instance, I don't know how to make program know that if "2" is the initialBase, that that means that the String is a binary number. THAT is what I'm having problems with.
Here is my initial program that has a few things that are copied and pasted from other bits of my code in my program:
XML Code: Url...
I have broken down what I (think I) need to do here: Check to see if the input base is 2, 8, 10, 16, or 32. Hint: Put the possible bases in an array, and check the input base against the array. Check to see if the input number is valid for the base. Hint: Create a String "0123456789ABC...V" and compare each input character with the first "base" characters of the String. Check to see if the output base is 2, 8, 10, 16, or 32. Hint: Use the same possible bases array you used in step 1 to verify the input base.Check to see if the input base is equal to the output base. If so, print the input number. Perform a conversion from the input base to base 10. Perform a conversion from base 10 to the output base. You do this in 2 steps because it's easier to check each conversion separately.Output the converted number.
I am trying to write a program for converting positive binary inputs into hex.Why am i getting this errors while compiling my binary to hex converter..
Exception in thread "main" java.lang.NumberFormatException: For input string: "148.0" at java.lang.NumberFormatException.forInputString(Num berFormatException.java:65) at java.lang.Long.parseLong(Long.java:441) at BinToHex.convertbintohex(BinToHex.java:24) at Test.main(Test.java:4)
Here is my BinToHex class
import java.io.*; public class BinToHex { double tempDec,fractionpart; long longofintpart,templongDec; String inpu ="1001.01"; String hexOutput,intpart,tempDecString,hex = null;
Write a program that will provide temperature conversions between degrees Fahrenheit and degrees Celsius. Provide a method that will take an argument representing a temperature in Fahrenheit degrees and return the equivalent temperature in degrees Celsius. Also provide a method that will take an argument representing a temperature in degrees Celsius and return the equivalent temperature in degrees Fahrenheit. Conversion formulas are as follows: F = 9./5. * C + 32, C = 5./9. * ( F - 32 ), where F = Fahrenheit temperature and C = Celsius temperature. You must prompt for input using the Input class methods that are provided as a download for this unit.
I have two questions, 1st is why won't I get an output from my program when I run it? 2nd is how do I prompt for input using the Input class methods downloaded? The downloaded files are in .class form, and won't show any output when I run them.My code is:
import java.util.*; public class temp { public static void main ( String [] args ) { Scanner in = new Scanner(System.in);
I'm working on creating the Binary to Decimal program . hat is wrong with this part of my code. Why does it not take you into the loop.
import java.util.Scanner; public class question5 { public static void main(String[] args) { System.out.println("Enter a Binary number. "); // collect Scanner keyb = new Scanner(System.in); //
A GUI program that allows user to enter their name and the program will convert it in number using array.
For example if i input "EUNISE" the output should be 521149195
Because the letter equivalent of
a = 1 b = 2 c = 3 d = 4 e = 5 f = 6 g = 7 h = 8 i = 9 j = 10 k = 11 l = 12 m = 13 n= 14 o = 15 p = 16 q = 17 r= 18 s = 19 t = 20 u = 21 v = 22 w = 23 x = 24 y = 25 z = 26
So i'm writing a for loop to convert any number entered to base 10 with any base provided as well. My code does not work because I need a way to reverse the code order, so the new number is printed correctly with the given base. My code so far:
public static void main (String[] args) { Scanner kb = new Scanner (System.in); System.out.print("Enter a number :: "); int numOriginal = kb.nextInt(); System.out.print("Enter a base :: "); int base = kb.nextInt();
[Code] .....
newBase has a problem with how it calculates the new number, looking for correct newBase code for conversion?