北邮国际学院大二Java实验-lab1
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Introdu
Course Cod
1. In a Jav or more
This pro
i) Mo
Your pr ii) Ca iii) Ca pro a.2. Write a the com stateme
the com uctory de: EBU4201va applicatio e String pa ogram outpu odify file Te java T rogram shou all the progra all the progra ogram call? .christie a Java progra mmand line ents or a swi mmand line to
Java P 1
n’s main()arameters. C uts the follow estArgs.j TestArgs ld be named am you just w
am again wit
For examp e . Try this wi am called We and prints o itch statem o an integer:
rogram Lab She method, St onsider the f wing when ca ava so that,Agatha C TestArgs wrote, Test th your own d ple, call the ith your deta eekDayCon out the corre ent. The foll mming eet 1: Jav tring[] a following Jav alled with ja , when called Christie s.java .
tArgs.java details. Wha e program w ails . Why do nverter th esponding da lowing line o Sch a Basics
args indica va program:
ava TestA d with 14213118a , with your at happens if with java you think yo hat reads an i ay of the we of code will c hool of Ele and Com ates that this Args howdy 8 1406756r own details you omit yo TestArgs ou got the res integer value eek. You ma convert the S ectronic En mputer Scie s method can dy : 601 it output .
our student nu Agatha sults you did e between 1ay use eithe String valu ngineering ence n take in one ts:
umber in the Christie d?
and 7 from er if…else ue read from e e e m e m
int weekDay = Integer.parseInt(args[0]);
Therefore, calling the program as follows:
java WeekDayConverter 4
will output:
The 4th day of the week is Thursday.
3. Write a program to calculate your BMI and give weight status. Body Mass Index (BMI) is an internationally used measurement to check if you have a healthy weight for your height. The metric BMI formula accepts weight in kilograms and height in metres, as follows:
BMI = weight(kg)/height 2(m 2)
BMI Weight Status categories’ table: BMI range – kg/m 2 Category
< 18.5
Underweight 18.5 – 24.9
Normal 25 – 29.9
Overweight ≥ 30 Obese
Use the command line arguments to give weight in kilograms and height in centimetres. For example:
java BMICalculator 80 175
should output:
Your weight: 80 kg
Your height: 1.75 m
Your BMI: 26.12
You are in the Overweight range.
Hint : The data you read from the command line argument is of type String , and to convert a String to an int , you must use the Integer.parseInt()
method; e.g. int anInt = Integer.parseInt(aString);
4. Below is a Java program that uses a while loop:
i) Write a new version of the program above using a do-while loop and name its file
DoublingNumbers1.java .
ii) Write a new version of the program above using a for loop and name its file
DoublingNumbers2.java .
Note : The three programs must have the same output.