Demo01 计算应缴纳金额
Demo02 计算该年该月天数
Demo03 打印图形
Demo04 打印图形
Demo05 打印图形
Demo06 打印99乘法表
Demo07 打印三位数中的所有水仙花数
import java.util.Scanner;
public class Demo01 {
public static void main(String[] args) {
/* 商场根据会员积分打折:
2000 分以内打 9 折,
4000 分以内打 8 折,
8000 分以内打 7.5 折,
8000 分以上打 7 折,使用 if-else-if 结构,实现手动输入购物金额和积分,
计算出应缴金额*/
Scanner scanner =new Scanner(System.in);
int Meony = 0; //金额
int Integral = 0;//积分
double actualMeony = 0;//应付金额
System.out.println("请输入金额:");
if(scanner.hasNextInt()) {
Meony = scanner.nextInt();}
else
{
System.out.println("输入有误!");
}
System.out.println("请输入积分:");
if(scanner.hasNextInt()) {
Integral = scanner.nextInt();}
else
{
System.out.println("输入有误!");
}
if(Integral<=2000)
{
actualMeony = Meony * 0.9;
}
else if(Integral<=4000&&Integral>2000)
{
actualMeony = Meony * 0.8;
}
else if(Integral<=8000&&Integral>4000)
{
actualMeony = Meony * 7.5;
}
else if(Integral>8000)
{
actualMeony = Meony * 7;
}
System.out.println("应付金额为:"+actualMeony);
}
import java.util.Scanner;
public class Demo02 {
public static void main(String[] args) {
/*一年中有 12 个月,而每个月的天数是不一样的。其中大月 31 天,分别为
1,3,5,7,8,10,12 月,小月 30 天,分别 为 4,6,9,11 月。还有二月比较特殊,平
年的二月只有 28 天,而闰年的二月有 29 天,由用户在控制台输入年份和月份,
程序计算该年该月的天数。*/
int year =0;//年份
int month =0;//月份
int days = 0;//天数
Scanner scanner =new Scanner(System.in);
System.out.println("请输入年份:");
if(scanner.hasNextInt())
{
year =scanner.nextInt();
}
else {
System.out.println("输入有误!");
}
System.out.println("请输入月份:");
if(scanner.hasNextInt())
{
month =scanner.nextInt();
}
else {
System.out.println("输入有误!");
}
//1. 闰年和平年的判断
//2. 两种选择结构
//闰年 二月24天
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:{
days =31;
}break;
case 4:
case 6:
case 9:
case 11:{
days =30;
}
case 2 :
{
if((year%4==0&&year%100!=0)||year%400==0)
{
days =29;//闰年
}
else {
days =28;//平年
}
}
}
System.out.println(month+"月的天数为"+days+"天");
}
}
public class Demo03 {
public static void main(String[] args) {
/*/
*
**
***
****
*****
/*/
//打印轮数
for(int i = 0;i < 5;i++)
{
//列
for(int j = 0;j<=i;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
public class Demo04 {
public static void main(String[] args) {
/* *****
****
***
**
*
*/
for(int i=0;i<5;i++)
{
for(int j =i;j<5;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
public class Demo05 {
public static void main(String[] args) {
/* *
***
*****
*******
*********
*/
for(int i=0;i<5;i++)
{
//空格
for(int j =0;j<5-i;j++)
{
System.out.print(" ");
}
//*
for(int j =0;j<2*i+1;j++)
{
System.out.print("*");
}
System.out.println();
}
}
}
public class Demo06 {
public static void main(String[] args) {
//打印9*9乘法表
for (int i = 1;i<=9;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(j+"*"+i+"="+i*j+"\t");
}
System.out.println();
}
}
}
import java.util.Scanner;
public class Demo07 {
public static void main(String[] args) {
//打印三位数中的所有水仙花数
Scanner scanner =new Scanner(System.in);
System.out.println("请输入一个三位数:");
int number = 0 ;
if(scanner.hasNextInt())
{
number =scanner.nextInt();
}
else {
System.out.println("输入有误!");
}
int ge,bai,shi=0;
ge = number % 10;//个
shi =number/10%10;//十
bai =number/100%10;//百
if(number == ge*ge*ge+shi*shi*shi+bai*bai)
{
System.out.println(number+"是水仙花数!");
}else {
System.out.println(number+"不是水仙花数!");
}
}
}
博客包含多个Java示例,有计算应缴纳金额、该年该月天数,还有打印图形、99乘法表,以及找出三位数中的水仙花数等内容,涉及基础的计算与输出操作。

340

被折叠的 条评论
为什么被折叠?



