SaidJan
پنج شنبه 20 شهریور 1393, 18:15 عصر
سلام
میخوام کاربر دما رو به صورت ۵۲f وارد کنه و دما رو به سانتیگراد تبدیل کنه و برعکس.
نمیخوام بین ۵۲f فاصله باشه.
اینو نوشتم اجرا میشه، دما رو هم وارد میکنم، ولی نتیجه رو نمید. مشکل از کجاس؟
قسمت for رو فک کنم باید حذف کنم و یه چیز دیگه اضاف کنم
import javax.swing.*;
import java.text.*;
import java.util.*;
class lab4 {
public static void main (String[ ] args) {
String tcf,cf,a,b;
double tc,tf;
Scanner scan = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.00");
JOptionPane.showInputDialog(null,"Enter the temp and a c or f (52f):" );
tcf = scan.next();
for(int i=0; i<tcf.length(); i++)
{
if (tcf.charAt(i)=='f'){
cf = tcf.substring (0,tcf.indexOf("f"));
double tt = Double.parseDouble(cf);
tc= tt* (9/5)+32;
System.out.print("The temperature in f is: "+ df.format(tc));
}
}
if (tcf.indexOf("f")!=-1)
{
cf = tcf.substring (0,tcf.indexOf("f"));
double tt = Double.parseDouble(cf);
tc= tt* (9/5)+32;
System.out.print("The temperature in c is: "+ df.format(tc));
}
if (tcf.indexOf("c")!=-1)
{
cf = tcf.substring (0,tcf.indexOf("c"));
double tt = Double.parseDouble(cf);
tf= (tt-32)*(5/9);
System.out.print("The temperature in f is: "+ df.format(tf));
}
}
}
میخوام کاربر دما رو به صورت ۵۲f وارد کنه و دما رو به سانتیگراد تبدیل کنه و برعکس.
نمیخوام بین ۵۲f فاصله باشه.
اینو نوشتم اجرا میشه، دما رو هم وارد میکنم، ولی نتیجه رو نمید. مشکل از کجاس؟
قسمت for رو فک کنم باید حذف کنم و یه چیز دیگه اضاف کنم
import javax.swing.*;
import java.text.*;
import java.util.*;
class lab4 {
public static void main (String[ ] args) {
String tcf,cf,a,b;
double tc,tf;
Scanner scan = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.00");
JOptionPane.showInputDialog(null,"Enter the temp and a c or f (52f):" );
tcf = scan.next();
for(int i=0; i<tcf.length(); i++)
{
if (tcf.charAt(i)=='f'){
cf = tcf.substring (0,tcf.indexOf("f"));
double tt = Double.parseDouble(cf);
tc= tt* (9/5)+32;
System.out.print("The temperature in f is: "+ df.format(tc));
}
}
if (tcf.indexOf("f")!=-1)
{
cf = tcf.substring (0,tcf.indexOf("f"));
double tt = Double.parseDouble(cf);
tc= tt* (9/5)+32;
System.out.print("The temperature in c is: "+ df.format(tc));
}
if (tcf.indexOf("c")!=-1)
{
cf = tcf.substring (0,tcf.indexOf("c"));
double tt = Double.parseDouble(cf);
tf= (tt-32)*(5/9);
System.out.print("The temperature in f is: "+ df.format(tf));
}
}
}