NEXT DAY 代码实现
package cn.edu.qfnu.ch01;
import java.util.Scanner;
public class nextday
{
public static void main(String[] args)
{
System.out.print(\"Enter year/month/day(空格间隔):\");
Scanner input=new Scanner(System.in);
int year=input.nextInt();
int month=input.nextInt();
int day=input.nextInt();
if(year<1812 || year>2012)
{
System.out.print(\"请输入1812~2012范围内的年份!\\n\");
}
if(1>month || month>12)
{
System.out.print(\"请输入1~12范围内的月份!\\n\");
}
if(1>day || day>31)
{
System.out.print(\"请输入1~31范围内的日期!\\n\");
}
else
{
System.out.print(\"你输入的 year is:\"+year+\" month is:\"+month+\" day is:\"+day+\"\\n\");
int tomorrowday = day,tomorrowmonth=month,tomorrowyear=year;
switch(month)
{
case (1):
case (3):
case (5):
case (7):
case (8):
case (10):
if(day<31)
{
tomorrowday=day+1;
}
else
{
tomorrowday=1;
tomorrowmonth=month+1;
}
System.out.print(\"Tomorrow's
is:\"+tomorrowyear+\"/\"+tomorrowmonth+\"/\"+tomorrowday);
break;
case 4:
case 6:
case 9:
case 11:
if(day<30)
date
{
tomorrowday=day+1;
}
else if(day==30)
{
tomorrowday=1;
tomorrowmonth=month+1;
}
else if(day==31)
{
System.out.print(month+\"月没有31天!\");
break;
}
System.out.print(\"Tomorrow's
is:\"+tomorrowyear+\"/\"+tomorrowmonth+\"/\"+tomorrowday);
date
break;
case 12:
if(day<31)
{
tomorrowday=day+1;
}
else if(day==31)
{
tomorrowday=1;
tomorrowmonth=1;
tomorrowyear=year+1;
}
System.out.print(\"Tomorrow's
is:\"+tomorrowyear+\"/\"+tomorrowmonth+\"/\"+tomorrowday);
date
break;
case 2:
if(day<28)
{
tomorrowday=day+1;
}
else if(day==28)
{
if((year%4==0 && year%100!=0) || year%400==0)
{
tomorrowday=29;
}
else {
tomorrowday=1;
tomorrowmonth=3;
}
}
else if(day==29)
{
if((year%4==0 && year%100!=0) || year%400==0)
{
tomorrowday=1;
tomorrowmonth=3;
}
else
{
System.out.print(year+\"是非闰年,2月份无29天!\");
break;
}
}
else if(day==30 || day==31)
{
System.out.print(\"2月份不含\"+day+\"天!\\n\");
break;
}
System.out.print(\"Tomorrow's
is:\"+tomorrowyear+\"/\"+tomorrowmonth+\"/\"+tomorrowday);
}
}
date
}
}
三角形问题:
package cn.edu.qfnu.ch01;
import java.util.Scanner;
public class sanjiaoxing
{
public static void main(String[] args)
{
System.out.print(\"请输入三角形的三条边的长度:\");
Scanner input=new Scanner(System.in);
int a=input.nextInt();
int b=input.nextInt();
int c=input.nextInt();
System.out.println(\"side a is:\"+a+\" side b is:\"+b+\" side c is:\"+c);
boolean istriangle=true;
if((a+b)<=c || (a+c)<=b || (c+b)<=a ||b<=1||b>=200||c<=1||c>=200)
{
istriangle=false;
}
if(istriangle==false)
{
System.out.print(\"Not a triangle(不是三角形)\");
}
else
{
a<=1||a>=200
||
if(a==b && a==c && b==c)
{
System.out.print(\"您输入的为等边三角形!\");
}
else if(a==b || a==c || b==c)
{
System.out.print(\"您输入的为等腰三角形!\");
}
else if(a!=b && a!=c && b!=c)
{
System.out.print(\"您输入的为一般三角形!\");
}
}
}
}
佣金问题:
package cn.edu.qfnu.ch01;
import java.util.Scanner;
public class yongjin
{
public static void main(String[] args)
{
double lockprice=45;
double stockprice=30;
double barrelprice=25;
double totallocks=0;
double totalstocks=0;
double totalbarrels=0;
double commission;
Scanner input=new Scanner(System.in);
System.out.print(\"Input the locks,stocks and barrels(空格间隔输入):\");
int locks=input.nextInt();
if(locks==-1)
{
System.out.print(\"当月销售活动结束!\\n\");
}
if(locks!=-1)
{
int stocks=input.nextInt();
int barrels=input.nextInt();
if(1>locks || locks>70)
{
System.out.println(\"对不起,机数不能为负数且厂商一个月只能卖出少于70个!\");
}
if(1>=stocks || locks>=80)
{
System.out.println(\"对不起,托数不能为负数且厂商一个月只能卖出少于80个!\");
}
if(1>=barrels || barrels>=90)
{
System.out.println(\"对不起,管数不能为负数且厂商一个月只能卖出少于90个!\");
}
totallocks=totallocks+locks;
totalstocks=totalstocks+stocks;
totalbarrels=totalbarrels+barrels;
System.out.print(\"Locks sold:\"+totallocks+\"\\nStocks
sold:\"+totalstocks+\"\\nbarrels sold:\"+totalbarrels+\"\\n\");
}
double locksales=lockprice*totallocks;
double stocksales=stockprice*totalstocks;
double barrelsales=barrelprice*totalbarrels;
double sales=locksales+stocksales+barrelsales;
System.out.print(\"total sales:\"+sales);
if(sales>1800)
{
commission=0.10*1000;
commission=commission+0.15*800;
commission=commission+0.20*(sales-1800);
}
else if(sales>1000)
{
commission=0.10*1000;
commission=commission+0.15*(sales-1000);
}
else commission=0.10*sales;
System.out.print(\"commission is $:\"+commission);
}
}
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- howto234.com 版权所有 湘ICP备2022005869号-3
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务