java class .method_java 调用类 method

小弟现在刚刚开始学习java,老师留了两道题,第一道题是C=5/9*(F–32)WhereFistheFahrenheittemperatureandCistheCelsiustemperature.WriteamethodnamedCelsiusthatacceptsasingleargu...

小弟现在刚刚开始学习java,老师留了两道题,

第一道题是

C= 5/9 * (F – 32)

WhereF is the Fahrenheit temperature and C is the Celsius temperature. Write a methodnamed Celsius that accepts a single argument, the temperature in Fahrenheit.The method should return the temperature converted to Celsius. Demonstrate themethod by calling it in a loop that displays a table of Fahrenheit temperatures0 through 20 and their Celsius equivalents.

现在我已经把这个转换写完了,但是不知道怎么可以加上这个table,然后这个method也不确定是否正确....

public static void main(String[] args) {

// TODO Auto-generated method stub

showTemperatures();

}

public static void showTemperatures()

{

int [] F = new int[21];

for(int i=0;i<21;i++)

{

F[i]=i;

double C = 5d/9d*(F[i]-32);

System.out.println("Fahrenheit Temperatire is:"+ " " +(i)+" " +"Celsius Temperatire is: "+ " " +C);

}

第二道题是

Convert program 3 in assignment 11 suchthat the average of the numbers in the array is computed in a method. Your main program should call a method calledaverage, passing the entire array. Themethod should compute the average of all numbers in the array and return theaverage to the caller. This methodshould be able to deal with any size array. Once main receives the average backfrom method average it should call another method to display the average.

之前的程序已经写好了,应该没有问题,但是这次的感觉有些晕,不知道能否帮助一二?

import java.util.Scanner;

import javax.swing.*;

public class LinhanYangProgram2

{

public static void main(String[] args) {

int b;

double sum=0;

System.out.print("How many numbers do you want to use to get a average:");

Scanner Keyboard = new Scanner(System.in);

b=Keyboard.nextInt();

if(b<=0)

{

JOptionPane.showMessageDialog(null,"The number you entered cannot be negative or 0");

}

if(b>0)

{

int[] a = new int[b];

{for (int i=0;i

{ if(b>0)

System.out.print("Please enter number"+(i+1)+" = ");

a [i]=Keyboard.nextInt();

sum=sum+a[i]; }

JOptionPane.showMessageDialog(null,"Average is" + sum/b, "result",1);}}}}

还需要继续完善程序,第一个题,是需要通过表格来呈现这些数据,但是我不知道该怎么把表格的程序加进去

第二个题是说在原有的程序上能够增加调用,就是在显示完一次平均数后,能够回到开始,准备显示下一次的平均数

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值