1、将百分制转为优秀良好
import java.util.Scanner;
public class MyTwelve {
public static void main (String [] args) {
Scanner input = new Scanner (System.in);
System.out.print ("请输入您的成绩:");
double score = input.nextDouble();
if ( score >= 90 ) {
System.out.println("优秀");
}else if ( score >= 80 ) {
System.out.println("良好");
}else if ( score >= 60 ) {
System.out.println("及格");
}else {
System.out.println("吃芥末");
}
}
}
2、输入三个数,比较大小, 将最大的输出
import java.util.Scanner;
public class MyTwelve {
public static void main (String [] args) {
Scanner input = new Scanner (System.in);
System.out.print ("请输入您的成绩:");
double score = input.nextDouble();
if ( score >= 90 ) {
System.out.println("优秀");
}else if ( score >= 80 ) {
System.out.println("良好");
}else if ( score >= 60 ) {
System.out.println("及格");
}else {
System.out.println("吃芥末");
}
}
}
3、输入三个数,按照从小到大排列并输出
方法1:
import java.util.Scanner;
/**
*输入三个整数,按照从小到大排列
*/
public class Test3 {
public static void main (String [] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入第一个数a:");
int a = input.nextInt();
System.out.print("请输入第二个数b:");
int b = input.nextInt();
System.out.print("请输入第三个数c:");
int c = input.nextInt();
//1、首先a>b (1)c和a相比 如果c大于a,bca
// (2)c和a相比 如果c小于a,还要看c和b相比,1)如果c大于b bca
// 2)如果b大于c cba
if(a>b){
//(1)c和a相比 如果c大于a,bca
if(c>a){
System.out.println("bac");
}else{
//(2)c和a相比 如果c<a
if(c>b){
//1)如果c大于b bca
System.out.println("bca");
}else{
//2)如果b大于c cba
System.out.println("cba");
}
}
//2、b>a c和b比较 (1)如果c大于b abc
// (2)如果c小于b c和a比较 1)c大于a acb
// 2)c小于a cab
}else{
if(c>b){
//(1)如果c大于b abc
System.out.println("abc");
//(2)如果c小于b c和a比较
}else{
if(c>a){
//1)c大于a acb
System.out.println("acb");
}else{
//2)c小于a cab
System.out.println("cab");
}
}
}
}
}
方法二:
import java.util.Scanner;
/**
*输入三个数,按照从小到大的顺序输出
*/
public class Test8 {
public static void main (String []args) {
int max;
Scanner input = new Scanner(System.in);
System.out.print("请输入第一个数字a:");
int a = input.nextInt();
System.out.print("请输入第二个数字b:");
int b = input.nextInt();
System.out.print("请输入第三个数字c:");
int c = input.nextInt();
//比较三个数的大小,首先比较两个数,再和第三个数比较;
//a和b比较
if(a>b){
//a为3 b是2 c为1
max = a;//a放到max=3
a = b;//b放到a=2
b = max;//max放到b=3
//执行之后 a = 2 b = 3
}
if(a>c){
//a为2 b是3 c为1 执行之后c = 2 a = 1
max = a;
a = c;
c = max;
}
if(b>c){
// a=1 b=3 c=2 执行之后 b=2 c=3
max = b;
b = c;
c = max;
}
System.out.print("从小到大:"+a+"<"+b+"<"+c);
}
}
4、输入一个年份,判断是平年还是闰年
import java.util.Scanner;
/**
*输入一个年份,判断闰年还是平年
能被4整除且不能被100整除;
能被400整除。
任意满足以上的条件之一就是闰年。
*/
public class Test4 {
public static void main (String [] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入一个年份:");
int years = input.nextInt();
if((years%4==0)&&!(years%100==0)||(years%400==0)){
System.out.println("闰年");
}else{
System.out.println("平年");
}
}
}
5、输入一个数, 判断是奇数还是偶数
import java.util.Scanner;
/**
*输入一个数,判断是奇数还是偶数
*/
public class Test5 {
public static void main (String [] args){
Scanner input = new Scanner(System.in);
System.out.print("输入一个整数:");
int number = input.nextInt();
if(number%2==0){
System.out.println("偶数");
}else{
System.out.println("奇数");
}
}
}
6、换算狗的年龄,前两年相当于人类的10.5岁,之后每一年相当于人类的4岁
import java.util.Scanner;
/**
*换算狗的年龄,前两年相当于人类的10.5岁,之后每一年相当于人类的4岁
*/
public class Test6{
public static void main(String [] args){
Scanner input = new Scanner(System.in);
System.out.print("请输入狗狗的年龄:");
int years = input.nextInt();
if( years > 2 ) {
double years1 = (years-2)*4+(2*10.5);
System.out.println("相当于人的年龄:"+years1);
}else if( (years>0) && (years<=2) ) {
System.out.println("相当于人的年龄:"+years*10.5);
}else if(years<0){
System.out.println("非法");
}
}
}
7、李蕾买手机需要7500,将自己的破手机抵押给新手机店,获得8折优惠;将破手机卖出,可获得1500,请问哪种实惠
/**
*李蕾买手机需要7900,将自己的破手机抵押给新手机店,获得8折优惠;将破手机卖出,可获得1500,请问哪种实惠
*/
import java.util.Scanner;
public class My7_6_6 {
public static void main (String []args){
//Scanner input = new Scanner(System.in);
//System.out.println("请输入你的选择: 1、选择优惠 2、卖掉");
//int num = input.nextInt();
double pay1 = 7900*0.8;
double pay2 = 7900 - 1500;
if (pay1<pay2){
System.out.println("选择优惠,一共需要花费"+pay1);
}else{
System.out.println("选择卖掉,一共需要花费"+pay2);
}
}
}
8、
*税前工资需要交0.1的三险一金
*三险一金后工资大于5000 需要交税
*缴费比例为超过5000的0~3000 0.03
* 超过5000的3000~12000 0.1
* 超过5000的12000~25000 0.2
* 超过5000的25000~35000 0.25
* 超过5000的35000~55000 0.3
* 超过5000的55000~80000 0.35
* 超过8000的部分交税 0.45
import java.util.Scanner;
/**
*税前工资需要交0.1的三险一金
*三险一金后工资大于5000 需要交税
*缴费比例为超过5000的0~3000 0.03
* 超过5000的3000~12000 0.1
* 超过5000的12000~25000 0.2
* 超过5000的25000~35000 0.25
* 超过5000的35000~55000 0.3
* 超过5000的55000~80000 0.35
* 超过8000的部分交税 0.45
*/
public class My7_6_10{
public static void main(String [] args){
Scanner input = new Scanner(System.in);
System.out.print("请输入你的工资:");
double solory = input.nextDouble();
//首先计算三险一金后工资
double solory1 = solory - solory*0.1;
//计算三险一金后多出5000多少
double solory2 = solory - solory*0.1 - 5000;
//判断三险一金后工资多出范围
if(solory2 >0){
if(solory2 <= 3000){
//计算交税
double solory3 = solory1 - solory2*0.03;
System.out.println("到手工资为:"+solory3);
}else if((solory2 > 3000) && ( solory2<=12000 )){
//计算交税
double solory3 = solory1 - solory2*0.1;
System.out.println("到手工资为:"+solory3);
}else if((solory2 <= 25000)&&(solory2 > 12000)){
//计算交税
double solory3 = solory1 - solory2*0.2;
System.out.println("到手工资为:"+solory3);
}else if((solory2 > 25000)&&(solory2 <= 35000)){
//计算交税
double solory3 = solory1 - solory2*0.25;
System.out.println("到手工资为:"+solory3);
}else if((solory2 <= 55000)&&(solory2 > 35000)){
//计算交税
double solory3 = solory1 - solory2*0.3;
System.out.println("到手工资为:"+solory3);
}else if((solory2 <= 80000)&&(solory2 > 55000)){
//计算交税
double solory3 = solory1 - solory2*0.35;
System.out.println("到手工资为:"+solory3);
}else if(solory2 > 80000){
//计算交税
double solory3 = solory1 - solory2*0.45;
System.out.println("到手工资为:"+solory3);
}
}else{
System.out.println("对不起,您不用交税!");
}
}
}