用java编写程序,定义两个float 变量C、F。计算公式C=5/9*(F-32)输入F输出C?

编写一个应用程序,定义两个float变量C,F。计算公式C=5/9(F-32),计算当F=60,F=90时,输出C的值~

用C语言写的,希望能帮到你哦!
#includevoid main(){float c,f;f=60;c=5/9.0*(f-32);printf("f=60时,c=%f
",c);f=90;c=5/9.0*(f-32);printf("f=90时,c=%f
",c);}

由于定义用“int” 为整型变量,在计算5/9是计算机默认结果为0,最好使用float或double来定义变量,在输入输出是注意改成“%f

public static void main(String[] args) throws Exception {
float C;
float F;
Scanner scanner = new Scanner(System.in);
System.out.println("请输入F:");
F = scanner.nextFloat();
C=5.0F/9*(F-32);
System.out.println("C="+C);
}

输入f求c?

Java程序设计:定义MyRectangle2D类,包含: •两个名为x和y的double型...
答:我的参考代码(代码写得不好请见谅,还有改进之处):MyRectangle2D.java (添加了一个获取四个关键点的方法)package com.test.test;import java.util.HashMap;import java.util.Map;public class MyRectangle2D { private int x; //矩形中心点x坐标 private int y; //矩形中心点y坐标 ...

编写两个java程序.
答:",");long sum = 0;for(int i=0; i<arr.length; i++){ sum += Integer.parseInt(arr[i]);} System.out.println("所有参数之和:" + sum);} } 运行测试:java TestArgs2 1,2,3,4,5 所有参数之和:15 注意:第二个程序的各个参数之间以逗号分开,不能有空格、跳格或回车。

java声明两个类,一个学生类,一个教师类,并输出相关信息
答://没用到访问器(set、get)public class TestClass { public static void main(String[] args) { //创建一个学生对象 Student xiaoming=new Student(2011001,"小明","打篮球、足球、玩游戏","175cm");//创建一个老师对象 Teacher wanglaoshi=new Teacher("Java","王老师","编程、业余黑客","...

编写一个Java程序,共有两个类
答:// Rectangle 类 / author JavaAlpha date 2011-10-12 version V 1.0 /public class Rectangle { private double width;private double height;private String color;//带有两个参数的构造方法 public Rectangle(double w, double h) { this.width = w;this.height = h;} //带有三个参数的...

编写一个JAVA程序,定义两个整型变量a,b并给它们赋初值,然后找出它们...
答:并什么?如果只要比较出最大最小值 可以用给定的最值方法 int n=Math.max(int a, int b);int n=Math.min(int a, int b);

编写一个Java应用程序,该程序中有2个类:Trangle、和Circle,分别用来描述...
答:Circle {private double radius;private double perimeter;private double area;public Circle(double radius) {this.radius = radius;this.perimeter = 2 * Math.PI * radius;this.area = Math.PI * radius * radius;}public double getRadius() {return radius;}public double getPerimeter(...

1编写一程序ShiJian2.java,分别定义两个矩阵,然后将两个矩阵相加,最后...
答:仅供参考,可以修改成符合自己的 public class TestMatrix{ public static void main(String[] args){ int[][] a={{1,2,3,4},{5,6,7,8},{9,1,2,3}};int[][] b={{1,2},{3,4},{5,6},{7,8}};int arow=a.length;int bcol=b[0].length;int m=b.length;int[][] c...

用JAVA编写 随机产生两个小于100的整数的加法运算式的程序
答:import java.util.*;public class P { public static void main(String[] args){ final int ScorePerExam=10;Scanner sc=new Scanner(System.in);Random r=new Random(Calendar.getInstance().getTimeInMillis());int n=0,right=0,wrong=0,num,sum,answer;boolean exit=false,jixu;S...

那位大哥帮我用JAVA写两个程序,
答:public class prg2 { public static void main(String argv[]) { int[] src = new int[] {5, 4, 5, 5, 6, 7, 4};ArrayList<Integer> dest = new ArrayList<Integer>();dest.add(src[0]); // 加入第一个元素 System.out.print(src[0]);for (int i = 1; i < src.length;...

编写一个Java程序,在程序中定义个Employee类,该类有两个私有属性:Strin...
答:class Employee{ private String name; private String address; public Employee(String name){ this.name = name; } public Employee(String name, String address){ this(name); this.address = address; } public void show(){ System.out.println("My name i...

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网