初学java 用if语句做几个小程序

import java.util.Scanner;
public class Var5{
/* public static void main(String[] args)//1.猜拳大战
{
Scanner input = new Scanner(System.in);
System.out.println("---------------------------------");
System.out.println("------------人机猜拳-------------");
System.out.println("---------------------------------");
System.out.println("0代表剪刀,1代表石头,2代表布");
System.out.println("请输入:");
int user = input.nextInt();
int computer=(int)(Math.random()*3);//随机数在0-3
if(user==0&&computer==2||user==1&&computer==0||user==2&&computer==1)
{
System.out.println("你是"+user+"电脑是"+computer+"恭喜你获胜");
}else if(user==computer)
{
System.out.println("你是"+user+"电脑是"+computer+"平局");
}else{
System.out.println("你是"+user+"电脑是"+computer+"你失败了");
}
}
}*/
/*public static void main(String[] args)//2.判断输入的5位数字是否是回文数字作业
{
Scanner input = new Scanner(System.in);
System.out.println("请输入一个5位数");
int num = input.nextInt();
if(num>=10000&&num<=99999)
{
int ge=num%10,shi=num/10%10,bai=num/100%10,qian=num/1000%10,wan=num/10000;
123
if(ge==wan&&shi==qian)
{
System.out.println(+num+"该数字是一个回文数");
}else{
System.out.println(+num+"该数字不是一个回文数");
}
}

else{
System.out.println("请输入一个合法五位数");
}
}
}*/
/* public static void main(String[] args){//3.根据用户输入的年份,月份,日期计算该日期是一年中的第几天?
Scanner input = new Scanner(System.in);
int run=0,total=0;//给值定义
int d=31,s=30;//d是单月30.s是双月31
System.out.println("请输入年份");
int year = input.nextInt();
System.out.println("请输入月份");
int month = input.nextInt();
System.out.println("请输入日期");
int day = input.nextInt();
if(year%4==0&&year%100==0||year%400==0){
run=1;
}if(month==1){
total=day;
}if(month==2){
total=d+day;
}if(month==3){
total=d+28+day+run;
}if(month==4){
total=d+28+run+d+day;
}if(month==5){
total=d+28+run+d+s+day;
}if(month==6){
total=d+28+run+d+s+d+day;
}if(month==7){
total=d+28+run+d+s+d+s+day;
}if(month==8){
total=d+28+run+d+s+d+s+d+day;
}if(month==9){
total=d+28+run+d+s+d+s+d+d+day;
}if(month==10){
total=d+28+run+d+s+d+s+d+d+s+day;
}if(month==11){
total=d+28+run+d+s+d+s+d+d+s+d+day;
}if(month==12){
total=d+28+run+d+s+d+s+d+d+s+d+s+day;

} System.out.println(+year+"年"+month+"月"+day+"号是一年中的"+total+"日");
}
}*/

/*public static void main(String[] args)//4.将用户输入的三个数字进行排序(降序)
{
Scanner input = new Scanner(System.in);
System.out.println("请输入一位数");
int a = input.nextInt();
System.out.println("请输入二位数");
int b = input.nextInt();
System.out.println("请输入三位数");
int c = input.nextInt();
System.out.println("排序前三位数是:"+a+b+c);
int temp;
if(a<c)
{
temp=a;
a=c;
c=temp;
}if(a<b)
{
temp=a;
a=b;
b=temp;
}if(b<c)
{
temp=b;
b=c;
c=temp;
}
System.out.println("排序后三位数是:"+a+b+c);

}
}*/

posted on 2017-03-30 21:00  流逝之羽  阅读(924)  评论(0编辑  收藏  举报

导航