public class Test {
創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供華坪網(wǎng)站建設(shè)、華坪做網(wǎng)站、華坪網(wǎng)站設(shè)計(jì)、華坪網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)與制作、華坪企業(yè)網(wǎng)站模板建站服務(wù),10多年華坪做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
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);
}
}
//好簡(jiǎn)單的程序,你要自己編~
public?class?Test?{
public?static?void?main(String?[]?args){
double?res;
Scanner?sc?=?new?Scanner(System.in);
System.out.println("請(qǐng)選擇:");
System.out.println("***********************");
System.out.println("輸入1從磅轉(zhuǎn)換千克:");
System.out.println("輸入2從千克轉(zhuǎn)換磅:");
System.out.println("***********************");
int?judgeNum?=?sc.nextInt();
System.out.println("請(qǐng)輸入你要轉(zhuǎn)換的數(shù)值:");
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;
}
}
按照題目要求編寫的磅轉(zhuǎn)換為千克的C語言程序如下
#includestdio.h
int main(){
float lb,kg;
printf("請(qǐng)輸入磅的重量數(shù):");
scanf("%f",lb);
kg=lb*453.6/1000;
printf("%f磅等于%f千克",lb,kg);
return 0;
}
#include iostream
#include string
using namespace std;
//沒用函數(shù)做
int main(int args,int argv)
{
int b=0;
cout"請(qǐng)輸入磅數(shù):";
cinb;
if(b=0)
{
cout b*0.454 "千克";
}
else
{
cout "請(qǐng)輸入正確磅數(shù)";
}
system("PAUSE");
}
真是好久沒碰了 用C++做的 不知道對(duì)不對(duì) 都沒VS了