|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I don't experience in programing could please help me
Write a program that will have a following menu 1.Convert fahrenheit to Celsius 2. Convert Celsius to Fahrenheit The formula for conversion is: fahrenheit=(9.0)/5)*celsius + 32 Celsius=(5/9)(f-32) import javax.swing.JOptionPane; publicclass temperatura { publicstaticvoid main (String[]args) { int temp; finalfloat fahrenheit,celsius; System.out.println("enter temperature celsius"); String input=JOptionPane.showinputDialog(null,"Enter your temperature in celsius", "fahrenheit",JOptionPane.QUESTION_MESSAGE); floatfahrenheit=parsefloat(input); if (temp == fahrenheit) { fahrenheit=(9.0/5)*temp+32; System.out.println("temperature in celsius"); JOptionPane.showinputDialog(null,"Enter your temperature in celsius", + celsius, "Output ",JOptionPane_INFORMATION_MESSAGE); } else (temp == celsius) { celsius=(5/9)*(temp -32); System.out.println("temperature in fahrenheit"); } JOptionPane.showinputDialog(null,"Enter your temperature in celsius", + celsius, "Output ",JOptionPane.INFORMATION_MESSAGE); } } |
|
#2
|
|||
|
|||
|
Ooops, I replied to the wrong person..... My Bad......Anyways.... Here's What I tried out today, maybe it will help you...... :
package Temperatura; import javax.swing.JOptionPane; public class temperatura { public static void main (String[] args) { String celsius; // first string entered by user String fahrenheit; // second string entered by user String temp; // third string by user int t; // else if variable double f; // fahrenheit variable used for both RESULT and celsius calculation double c; // celsius variable used for both RESULT and fahrenheit calculation celsius = JOptionPane.showInputDialog( "Enter the temperature in celsius: "); fahrenheit = JOptionPane.showInputDialog("Enter the temperature in fahrenheit: "); c = Double.parseDouble(celsius); f = Double.parseDouble(fahrenheit); //attempt a menu to calculate either celsius or fahrenheit temp = JOptionPane.showInputDialog("Enter which temp to calculate 1. celsius or 2. fahrenheit "); // check menu number for correct t value t = Integer.parseInt(temp); JOptionPane.showMessageDialog(null, "You entered: " + t, "RESULTS", JOptionPane.PLAIN_MESSAGE); if (t == 1) //calculate fahrenheit { f =(9.0/5)*c + 32; // display result JOptionPane.showMessageDialog(null, "The temperature in fahrenheit is: " + f, "RESULTS", JOptionPane.PLAIN_MESSAGE); } else if (t == 2) // calculate celsius { c = ((5.0/9) * (f - 32)); JOptionPane.showMessageDialog(null, "The temperature in celsius is: " + c, "RESULTS", JOptionPane.PLAIN_MESSAGE); } JOptionPane.showMessageDialog(null, "That's all Folks\nOK I had fun learning this also,\nI'm addicted... I admit it....lol!!!"); // enter silly message here System.exit(0); }// end main }// end class temperatura |
|
#3
|
||||
|
||||
|
Try using [code][/code] tags when posting your code to the forum.
These tags are designed to keep your indents and code structure. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > could please help to write a program using loop (if-else) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|