java基础第五章上机题_accp6.0JAVA1第五章上机练习(Accp6.0JAVA1 fifth chapter on the machine practice).doc...

这篇博客包含了三个Java程序实例,分别演示了不同类型的循环(while, do-while, for)和条件判断(if, switch)。第一个程序计算1到100的和,第二个程序累加能被3整除的数直到1000,第三个程序接收用户输入并找出最大值和最小值。此外,还展示了商品销售系统中根据用户选择计算总价的案例。
摘要由CSDN通过智能技术生成

accp6.0JAVA1第五章上机练习(Accp6.0JAVA1 fifth chapter on the machine practice)

accp6.0JAVA1第五章上机练习(Accp6.0JAVA1 fifth chapter on the machine practice)

Public class Text1 {

/ * *

* @ param args

* /

Public static void main (string [] args) {

/ / all self generated method stub

Int a = 1;

Int sum = 0;

While (< = 100) {

Sum = sum +;

A + +;

If (a = = 101) {

System.out.println ("结果是:" + sum);

}

}

}

}

Public class text2 {

/ * *

* @ param args

* /

Public static void main (string [] args) {

/ / all self generated method stub

Int a = 0;

Int sum = 0;

While (< = 1000) {

If (a% 3 = = 0) {

Sum = sum +;

}

A + +;

}

System.out.println ("结果为:" + sum);

}

}

Import java.util.scanner;

Public class Text4 {

/ * *

* @ param args

* /

Public static void main (string [] args) {

/ / all self generated method stub

Int max = 0, min = 100000;

The scanner input = new scanner (system.in);

Int i = 0;

{

System.out.print ("请输入一个数字 (输入0结束):");

I = input.nextint ();

If (I = = 0)

Break;

If (I > Max {

Max = I;

}

If (I < min) {

Min = I;

}

} while (true);

System.out.println ("最大值是:" + + ", 最小值是 Max:" + min);

}

}

Import java.util. *;

Public class text9 {

/ * *

* @ param args

* /

Public static void main (string [] args) {

/ / all self generated method stub

The scanner input = new scanner (system.in);

String a;

Int bianhao;

Int Shuliang;

Int anount = 0;

Double txue = 245;

Double wangqiuxie = 570;

Double wangqiupai = 320;

Double discount = 0.8;

Double total = 0.0;

The double payment = 0.0;

Double Zhaoqian = 0.0;

System.out.println ("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");

System.out.println ("请选择购买的商品编号:");

System.out.println ("1.t恤 \ t2.网球鞋 \ t3.网球拍");

System.out.println ("* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *");

{

System.out.print ("请输入商品编号:");

Bianhao = input.nextint ();

System.out.println ("请输入购买数量");

Shuliang = input.nextint ();

The switch (bianhao) {

Case 1:

System.out.println ("t恤" + + "txue \ t数量" + + "Shuliang \ t合计"

+ txue * Shuliang);

Break;

Case 2:

System.out.println ("网球鞋" + + "wangqiuxie

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值