今天学习了JAVA语言的一些基本的语法,运算符等等
其中按位或预算符 |
按位异或预算符 ^
左移运算符 <<
右移运算符 >>
无符号右移运算符>>>
这是几个基本的之前接触较少的运算符
其他的就是和之前学习的语言 相差不大的一些知识
在此也就不再一一列举了
之后完成了一个小学期的程序
是一个小游戏
在此附上代码
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{
int t1,t2, x, a, s, z, q;
srand((unsigned)time(NULL));
do
{
s = rand()%100+1;
cout << "请设置时间:";
cin >> q;
t1 = time(NULL);
cout << "请输入您猜的数字:";
cin >> x;
while (x != s)
{
cin >> x;
if (x < s)
{
cout << "低了" << endl;
t2 = time(NULL);
q = q - (t2 - t1);
cout << "您的剩余时间:";
if (q <= 0)
cout << "0" << endl;
else
cout << q << endl;
}
else if (x > s)
{
#include <stdlib.h>
#include <time.h>
using namespace std;
int main()
{
int t1,t2, x, a, s, z, q;
srand((unsigned)time(NULL));
do
{
s = rand()%100+1;
cout << "请设置时间:";
cin >> q;
t1 = time(NULL);
cout << "请输入您猜的数字:";
cin >> x;
while (x != s)
{
cin >> x;
if (x < s)
{
cout << "低了" << endl;
t2 = time(NULL);
q = q - (t2 - t1);
cout << "您的剩余时间:";
if (q <= 0)
cout << "0" << endl;
else
cout << q << endl;
}
else if (x > s)
{
cout << "高了" << endl;
t2 = time(NULL);
q = q - (t2 - t1);
cout << "您的剩余时间:";
if (q <= 0)
cout << "0" << endl;
else
cout << q << endl;
}
if (q == t1|| q <= 0)
break;
}
t2 = time(NULL);
q = q - (t2 - t1);
cout << "您的剩余时间:";
if (q <= 0)
cout << "0" << endl;
else
cout << q << endl;
}
if (q == t1|| q <= 0)
break;
}
if (q == t1 || q <= 0)
cout << "很遗憾,未能在规定时间内猜出正确数字,该数字是:" << s << endl;
else
cout << "恭喜!正确猜出数字" << s << endl;
cout << "是否继续游戏" << endl;
cout << "输入“1”继续游戏" << endl;
cin >> a;
} while (a == 1);
cout << "您选择不进行游戏" << endl;
system("pause");
return 0;
}
cout << "很遗憾,未能在规定时间内猜出正确数字,该数字是:" << s << endl;
else
cout << "恭喜!正确猜出数字" << s << endl;
cout << "是否继续游戏" << endl;
cout << "输入“1”继续游戏" << endl;
cin >> a;
} while (a == 1);
cout << "您选择不进行游戏" << endl;
system("pause");
return 0;
}
这是一个猜数游戏
首先由玩家设置游戏时间
系统会随机取一个数
然后由玩家猜
这样一个简单的小程序