|登录 |注册

查看: 915|回复: 4
打印 上一主题 下一主题

java 程序,,救命!!:(

[复制链接]
007pig
2013-12-2 11:08 PM
public class replyq2{
        public static void main(String[]args){
               
                System.out.println("" +celsiusToFahrenheit);
                System.out.println("" +fahrenheitToCelsius);

        }
       
        public static double celsiusToFahrenheit (double celsius){
                for(celsius=40;celsius>31;celsius++)
                celsius=(celsius*9/5)+32;
                return celsius;
        }
       
       
       
        public static double fahrenheitToCelsius (double fahrenheit){
                for(fahrenheit=120;fahrenheit>30;fahrenheit++)
                fahrenheit=(fahrenheit-32)*5/9;
                return fahrenheit;
        }
}


求大神教教我怎么把System.out.println("" +celsiusToFahrenheit);
                System.out.println("" +fahrenheitToCelsius);
丢去给下面处理,然后print出下面运算好的答案
OK!Lah!!
2013-12-2 11:54 PM
看起来你要做的东西大概是这样=。=



private double celsius;
private double fahrenheit;

public class replyq2{
        public static void main(String[]args){
               
              celsiusToFahrenheit();
              fahrenheitToCelsius ()
        }
        
         public static void celsiusToFahrenheit (){
                for(celsius=40;celsius>31;celsius++)
                celsius=(celsius*9/5)+32;
                System.out.println("" +celsiusToFahrenheit);
               
        }
        
        
        
        public static void fahrenheitToCelsius (){
                for(fahrenheit=120;fahrenheit>30;fahrenheit++)
                fahrenheit=(fahrenheit-32)*5/9;
                System.out.println("" +fahrenheitToCelsius);
        }
}
游戏玩家
2013-12-3 12:34 AM
你要的是不是这样?
public static void main(String[]args){
               
                System.out.println(celsiusToFahrenheit(37));
                System.out.println(fahrenheitToCelsius(220));
        }

还有你的for loop好像会infinite loop
话说你也好像不用用到loop吧
slay_alex92
2013-12-3 08:40 PM
本帖最后由 slay_alex92 于 2013-12-3 09:01 PM 编辑

我15行就搞定了 你看一下
  1. public class q2
  2. {
  3.         public static void main(String[] args){
  4.                 System.out.println(celsiusToFahrenheit(50));
  5.                 System.out.println(fahrenheitToCelsius(100));
  6.         }
  7.        
  8.         public static double celsiusToFahrenheit(double celsius){
  9.                 return celsius * 9 / 5 + 32;
  10.         }
  11.        
  12.         public static double fahrenheitToCelsius(double fahrenheit){
  13.                 return (fahrenheit - 32) * 5 / 9;
  14.         }
  15. }
复制代码
youthisbaka
2014-2-9 12:15 PM
  1. public class replyq2{
  2.         public static void main(String[]args){
  3.                
  4.                 celsiusToFahrenheit(32);
  5.                 fahrenheitToCelsius(90);
  6.         }
  7.         
  8.          public static void celsiusToFahrenheit (double celsius){     
  9.                 System.println(celsius=(celsius*9/5)+32);
  10.         }
  11.         
  12.         public static void fahrenheitToCelsius (double fahrenheit){
  13.                 System.println((fahrenheit-32)*5/9);
  14.         }
  15. }
复制代码
应该是没有错的
您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2026-1-1 10:36 AM , Processed in 0.118893 second(s), 21 queries .

Powered by Discuz! X2.5 © 2001-2012 Comsenz Inc.

本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved

Dedicated Server powered by iCore Technology Sdn. Bhd.

合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部