积分卡+计算月的天数+打印三角形+99乘法表+水仙花数

博客包含多个Java示例,有计算应缴纳金额、该年该月天数,还有打印图形、99乘法表,以及找出三位数中的水仙花数等内容,涉及基础的计算与输出操作。

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+"不是水仙花数!");
	}
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我想去拉萨。

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值