📄 assignonec05.java
字号:
//********************************************************************************************
// AssignOneC05.java Author:Mary
//UTAS ID number:066748 Date:Oct 25th
//ZJUT ID number:200419100234
//Demonstrates the use of readString method of Keyboard class to read strings from the user
//and use of the loop sentences
//********************************************************************************************
import cs1.Keyboard;
public class AssignOneC05
{
//----------------------------------------------------------------------------------------
//read the strings,numbers,name and print the fortune telling
//----------------------------------------------------------------------------------------
public static void main(String[] args)
{
int mag_num,fnumber,count=0;//reference mag_num,fnumber and instatial count
final int SECRET_NUMBER=5; //declare the reference variable and instatiation
final String SECRET_COLOUR="purple";
String name,fcolour1,fcolour,again="y";//reference variables
while (again.equals("y")||again.equals("Y"))//do the loop
{
System.out.println("Enter the favourite number:");
fnumber=Keyboard.readInt();
System.out.println("Enter the name:");
name=Keyboard.readString();
System.out.println("Enter the favourite colour:");
fcolour1=Keyboard.readString();
fcolour=fcolour1.toLowerCase();
mag_num=(name.length()+SECRET_COLOUR.length())%5;
System.out.println("the magic number is"+mag_num);
if((mag_num==fnumber)&&fcolour.equals(SECRET_COLOUR))
{
System.out.println("Today is your lucky day.");
}
else
{
if (mag_num>=fcolour.length()/2||mag_num>fcolour.length())
{
System.out.print("Be careful when crossing the road.");
}
else
{
System.out.println("Work hard and you will be sucessful.");
}
}count++;
System.out.println("Do you want to try again,if you want to try enter y:");
again=Keyboard.readString();
}
System.out.println("you have played"+count+"fortunes.");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -