这个题因为计算中带有小数所以我们采用double类型,先判断dalt然后再根据公式计算
import java. util. Scanner ;
public class ti31 {
public static void main(String[] args) {
System. out . println("Enter a,b,c");//提示用户输入
double a,b,c;//定义
Scanner in = new Scanner(System.in);
a = in. nextDouble();//读取数据
b = in.nextDouble();
C = in.nextDouble();
double d = b*b-4*a*c;//计算看有几个实数根
double e = -b+Math. pow(d, 0.5);
double f = -b-Math. pow(d, 0.5);
if (d<0) //判断
System. out . println("No realroots");
if (d==0)
System. out . println("have one root:"+e/2*a);
if (d>0)System. out . println("have two root:"+e/2*a+" and "+f/2*a);
}
;
这个题和第一题类似,牵扯小数,所以用double型定义变量
import java. util . Scanner;
public class ti32 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System. out .println("Enter a,b,c,d,e,f");//提示用户输
double a,b,c,d,e,f;//定义
Scanner in = new Scanner(System. in);
a = in. nextDouble();//读取所有数据
b = in.nextDouble();
C = in.nextDouble();
d = in.nextDouble();
e = in.nextDouble();
f = in.nextDouble();
if (a*d-b*c == 0)//判断是否有解
{
System. out . println("方程式无解");
}
//.如果有解输出
else
{
double q=a*d-b*c;
double x = (e*d-b*f)/q;
double y = (a*f-e*c)/q;
System. out. println("x = "+x+" y = "+y);
}
}
这个题主要就是(今天地星期数)+未来的天数
然后将和对7取余
最后还存在一个从数到文字的转化问题无论是switch还是if 均可解决
1mport Java●ut1l. Scanner;
public class ti33 {
public static void main(String[] args) {
Scanner in = new Scanner (System.in);
System. out .print("今天是周几? 0为周日...");//提示用户输入
int today = in.nextInt();
system. out. print("输入未来几天? ");//提示用户输入
int future = in. nextInt();
int futureday = (today+future)%7;// 获取未来几天的星期
string todaystr =”";//定义今天的星期,将数字转换为星期
if (today == 0 ) todaystr = "周日";
else if (today == 1)todaystr =“周一";
else if (today == 2)todaystr=“周二”;
else if (today == 3)todaystr = "周三";
else if (today == 4)todaystr = "周四";
else if (today == 5)todaystr = "周五";
else if (today == 6) todaystr = "周六";
String futerstr =”";//定义未来的星期,将数字转换为星期
if (futureday == 0 ) futerstr = "周日”;
else if (futureday == 1)futerstr = "周一";
else if (futureday == 2)futerstr= "周二”;
else if (futureday == 3)futerstr = "周三";
else if (futureday == 4)futerstr = "周四";
else if (futureday == 5)futerstr = "周五”;
else if (futureday == 6)futerstr = "周六";
//系统输出结果
System. out . print("今天是"+todaystr+"”+future+"天后是"+futureday).
}
这个题首先要牵扯随机数
可以通过设Math.random这个类来实现然后在后面标注范围
或者是通过Random nextInt(n)
之后就是比较和输出
import java.util.*;
public class ti36 {
public static void main(String[] args) {
Random random=new Random();//定 义随机数对象
int a = random. nextInt(3);//产生2以内的随机数
Scanner in = new Scanner (System. in);
System. out . println("输入0/1/2分别代表石头剪刀布");//提示用户输入
int b = in.nextInt();//读取数据
if (a==0)
//判断哪个人赢了
{
if (b==0)
System. out . println(”我是石头你是石头平了");
if (b==1)
System. out . println("我是石头你是剪刀你输了”
if (b==2)
System. out .println("我是石头你是布你赢了");
if (a==1)
{
if (b==0)
System. out .println("我是剪刀你是石头你赢了”
if (b==1)
System. out .println("我是剪刀你是剪刀平了");
if (b==2)
System. out . println("我是剪刀你是布你输了");
}
if (a==2)
{
if (b==0)
System. out . println("我是布你是石头你输了");
if (b==1)
System. out . println("我是布你是剪刀你赢了");
if (b==2)
System. out .println("我是布你是布平了");
}
}
import java. util. Scanner;
public class ti34 {
public static void main(String[] args) {
Scanner in = new Scanner (System. in);
System. out .println("输入三位数字");//提示用户输入
int a,b,c,num,k;//定义变量
k = in.nextInt();//读取数字
num = k;//将数字备份
a = num%10;//取余
num/=10;//除以10
b = num%10;//
num/=10;//
C = num%10;//取余
if (a==c)//看是否相等
System. out . println(k+"是回文数字");//输出结果
else System. out . print1n(k+"不是回文数字");
首先随机生成两位数,考虑到底一维数组可能是所以在生成小于的数时我们要将第一位当作0
import java. util. Scanner;
public class ti35 {
public static void main(String[] args) {
Scanner in = new Scanner (System. in);
int num=(int) (Math. random( )*100);//取- - 个随机数
System. out . println("输入两位数字");//提示用户输入
int c;
intk=0;
c = in.nextInt();//用户输入的数字
int e,f;
int e,f;
if (<<0) //如果是10以内的第一 位是0
e=0.
f= c;
else
f = C%10;
c/=10;
e =C;
}//进行第- -位和第 二位数字的赋值
int a,b;
if (num<10)
a=0
b = num;
}
else
b
= num%10;
num/=10;
a = num;
}
if (a==e&&b==f)
System. out . println("10000");//- -等奖
else if (a == f &&b==e)
System. out .println("3000");//二等奖
else if (a==e||a==f||b==e||b==f)
System. out .print1n("1000");//三等奖
这个题很简单我们只需要输入然后代数公式就行
import java.util.*;
public class ti37 {
public static void main(String[] args) {
int h;
System. out.print("输入年月该月第几天");//提示用户输入
Scanner in = new Scanner (System. in);
int year = in.nextInt();//定义数据
int m = in.nextInt();
int q = in.nextInt();
if (m==1) //特殊情况,年份减,月份边=变13
{
year--;
m =13;
}
if (m == 2) //特殊情况,年份减,月份边= 变14
year--;
m =14;
}
int j = year/100;
int k = year%100;
h = (q+26*(m+1)/10+k+k/4+j/4+5*j)%7;//代入公式
if (h==0)System. out. println("周六");//将数字变为星期几
else if (h==1 )System. out. println("周天");
else if (h==2)System. out. println("周- ");
else if (h==3)System. out. println("周二");
else if (h==4)System. out. println("周三");
else if (h==5)System. out. println("周四");
else System. out . print1n("周五");
这个题主要就是计算输入的点和圆心距里的距离,然后和半径进行比较。
import java.util.*;
public class ti38 {
public static void main (String[
args) {
Scanner in = new Scanner (System. in);
System. out .println( "输入坐标点");//提示用户输入
double x = in. nextDouble();//读取坐标
double y = in. nextDouble();
double xo = 0;//定义圆心
double yo = 0;
double radius = 10;//定义半径
//计算距离
double distance =Math. sqrt( Math. pow(x-xo,2)+Math. pow(y-yo,2));
if (distance == radius) //距离相等
System. out .println("在圆上");
else if (distance > radius) //在圆外
System. out. println("在圆外");
else //在圆内
System. out . println("在圆内");
}