public class Test {
创新互联专业为企业提供华坪网站建设、华坪做网站、华坪网站设计、华坪网站制作等企业网站建设、网页设计与制作、华坪企业网站模板建站服务,10多年华坪做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
public double change(double bang) {
double kg = bang * 0.454;
return kg;
}
public static void main(String[] args) {
Test test = new Test1();
double bang = 5.23;
double kg = test.change(bang);
System.out.print(kg);
}
}
//好简单的程序,你要自己编~
public class Test {
public static void main(String [] args){
double res;
Scanner sc = new Scanner(System.in);
System.out.println("请选择:");
System.out.println("***********************");
System.out.println("输入1从磅转换千克:");
System.out.println("输入2从千克转换磅:");
System.out.println("***********************");
int judgeNum = sc.nextInt();
System.out.println("请输入你要转换的数值:");
int num = sc.nextInt();
switch(judgeNum){
case 1:
res = poundsToKilo(num);
System.out.println(num+" pounds is "+ res +" kilograms");
break;
case 2:
res = kiloToPounds(num);
System.out.println(num+" kilograms is "+ res + " pounds");
break;
default :
System.out.println("answer is invalid .");
}
}
static double poundsToKilo(int num){
return num*0.45359237;
}
static double kiloToPounds(int num){
return num*2.2046226218488;
}
}
按照题目要求编写的磅转换为千克的C语言程序如下
#includestdio.h
int main(){
float lb,kg;
printf("请输入磅的重量数:");
scanf("%f",lb);
kg=lb*453.6/1000;
printf("%f磅等于%f千克",lb,kg);
return 0;
}
#include iostream
#include string
using namespace std;
//没用函数做
int main(int args,int argv)
{
int b=0;
cout"请输入磅数:";
cinb;
if(b=0)
{
cout b*0.454 "千克";
}
else
{
cout "请输入正确磅数";
}
system("PAUSE");
}
真是好久没碰了 用C++做的 不知道对不对 都没VS了