01/10/2018, 14:25
Code "iteration and switch statements to print the song" bị sai kết quả
cho em hỏi đoạn code này em viết mà em thấy bị lỗi lỗi sao á. Mong anh em chỉ bảo.
Cái này là mình viết in ra cái lyric của 1 bài nhạc. Trong bài tập này, chương trình mình phải có cái yêu cầu " iteration and switch statements to print the song". Lúc mình run nó hỏi bao nhiêu cái copy, mình bấm 2, mà nó in ra cả đống. Mình thử số khác cũng dậy. Mình muốn thí vụ mình bấm 4 cái, thì nó hiện ra 4 cái copy, chứ không phải 1 đóng. Mong anh em chỉ giáo.
import java.util.Scanner;
public class mrle
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
String song = "";
System.out.print("please Enter the of gits you want:");
int Gits = input.nextInt();
for(int count = 1; count <=12; count++)
{
song = song + "on the ";
switch(count)
{
case 1:
song = song + "first";
break;
case 2:
song = song + "second";
break;
case 3:
song = song + "third";
break;
case 4:
song = song + "fourth";
break;
case 5:
song = song + "fifth";
break;
case 6:
song = song + "sixth";
break;
case 7:
song = song + "seventh";
break;
case 8:
song = song + "eghith";
break;
case 9:
song = song + "ninth";
break;
case 10:
song = song + "tenth";
break;
case 11:
song = song + "eleventh";
break;
case 12:
song = song + "twelfth";
break;
}
song = song + "day of Christmas my true love sent to me
";
switch(count)
{
case 12:
song = song + "Eight maids a-milking
";
case 11:
song = song + "Five gold rings
";
case 10:
song = song + "Two turtle doves, and
";
case 9:
song = song + "Twelve drummers drumming
";
case 8:
song = song + "Eight maids a-milking
";
case 7:
song = song + "Seven swans a-swimming
";
case 6:
song = song + "Six geese a-laying
";
case 5:
song = song + "A partridge in a pear tree
";
case 4:
song = song + "TEight maids a-milking
";
case 3:
song = song + " Three french hens
";
case 2:
song = song + " Two turtle doves
";
case 1:
song = song + "A partridge in a pear tree
";
break;
}
}
System.out.println(song);
}
}
Bài liên quan
bạn có thấy cái số bạn nhập vào nó vô dụng không
Nên giới hạn
gits
(gifts :D) luôn.Để output chuẩn thì thêm chỗ case 1 (1st day) chữ “and”.