- 9
- 0
- 约3.84千字
- 约 14页
- 2017-12-17 发布于河南
- 举报
java songs代码详解
李义第九周作业
a. 编写一个输出“Ninety-nine Bottles of Beer on the Wall.”歌词(不知道没关系,其实我也不知道,不过你认真看下去就会知道)的程序。程序应当以英文的形式打印瓶数,而不是数字。例如:
Ninety-nine bottles of beer on the wall,
Ninety-nine bottles of beer,
Take one down, pass it around,
Ninety-eight bottles of beer on the wall.
...
One bottle of beer on the wall,
One bottle of beer,
Take one down, pass it around,
Zero bottle of beer on the wall.
(bottle的单复数形式不用管它了,当然,能注意到最好)
程序不能使用99个输出语句!
应为程序设计一个称为BeerSong的类,它的构造方法取一个整型参数,该参数的初值是墙上的啤酒瓶数。如果该参数小于0,则将瓶数设为0。类似的,如果该参数大于99,则将啤酒瓶数设为99。然后编写一个称为PrintSong的共有方法,输出每一节中的啤酒瓶数,直到0为止。可以添加任何其它有帮助的私有方法。
我的答案:
我的答案:
import java.util.Scanner;
public class BeerSong {
static String[] onetotwenty={
,one,two,three,four,five,six,seven,eight,nine,
Ten,Eleven, twelve ,Thirteen,Fourteen,Fifteen,Sixteen,Seventeen,
Eighteen,Nineteen,Twenty
};
static String[] twentytoninety={
Twenty,Thirty,Fourty,Fifty,Sixty,Seventy,Eighty,Ninety
};
public static void main(String args[]){
//String[] str={goods,happy};
System.out.println(请输入一个数:);
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
if(n99) n=99;
else if(n0) n=0;
int m=n/10,q=n%10;
if(n20)
{
for(int i=m-2;i=0;i--)
{
for(int j=q;j=0;j--)
{
int a=i,b=j;
if(j==0) q=9;
if(!(i==0j==0))
{
System.out.println(twentytoninety[i]+-+onetotwenty[j]+ bottles of beer on the wall,);
System.out.println(twentytoninety[i]+-+onetotwenty[j]+ bottles of beer, );
System.out.println(Take one down,pass it around,);
int p=j-1;
if(p0i0) {i--;p=9;}
System.out.println(twentytoninety[i]+-+onetotwenty[p]+ bottles of beer on the wall.);
System.out.println(----------------------------------);
i=a;j=b;
}
}
}
for(int k=19;k0;k--)
{
System.out.println(onetotwenty[k]+ bottles of beer on the wall,);
System.out.println(onetotwenty[k]+ bottles of beer ,);
System.out.println(Take one down,pass it around,);
if(k1)
System.out.println(onetotwenty[k-1]+bottles of beer o
您可能关注的文档
- 专题四 初中英语数词.doc
- 2008年职称英语考试卫生类B级试题.doc
- ansys模拟起皱现象的主要步骤与分析说明.doc
- 初2012级英语寒假作业.doc
- 七年级英语法制教育渗透教案(杨龙)Microsoft_Word_文档.doc
- japan-原文.doc
- 罗红彦法制教育渗透教案Microsoft-Word-文档.doc
- 新航道专转本_英语_数词.doc
- after effects 简介.docx
- NOKIA MGW IPA2800硬件结构(浙江移动).doc
- 2025-2026学年天津市和平区高三(上)期末数学试卷(含解析).pdf
- 2025-2026学年云南省楚雄州高三(上)期末数学试卷(含答案).pdf
- 2025-2026学年甘肃省天水市张家川实验中学高三(上)期末数学试卷(含答案).docx
- 2025-2026学年福建省厦门市松柏中学高二(上)期末数学试卷(含答案).docx
- 2025-2026学年广西钦州市高一(上)期末物理试卷(含答案).docx
- 2025-2026学年河北省邯郸市临漳县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省石家庄二十三中七年级(上)期末历史试卷(含答案).docx
- 2025-2026学年海南省五指山市九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省唐山市玉田县九年级(上)期末化学试卷(含答案).docx
- 2025-2026学年河北省邢台市市区九年级(上)期末化学试卷(含答案).docx
最近下载
- 幽默卡通动漫笑点设计方法.docx VIP
- 行星式球磨机立式-FOCUCY弗卡斯.PDF VIP
- 贵州省六校联考2025届高三下学期3月高考实用性联考(四)英语试卷(含答案).docx VIP
- 颈椎病的中医护理课件.pptx VIP
- 原调正谱G小小蝴蝶la farfalletta钢琴伴奏高清打印版.pdf VIP
- 上海大学2024-2025学年第1学期《高等数学(上)》期末考试试卷(B卷)附参考答案.pdf
- 广发证券-交通银行-601328-零售转型提速,定增落地夯实资本根基.pdf
- 上海大学2024-2025学年第1学期《高等数学(上)》期末考试试卷(A卷)附参考答案.pdf
- 循环系统护理小讲课.pptx
- 建筑屋面西瓦专项施工方案(范本).doc VIP
原创力文档

文档评论(0)