3道Java算法编程题(三)

【程序11    题目:有1234四个数字,能组成多少个互不相同且一个数字中无重复数字的三位数?并把他们都输入。   

 public class lianxi11 { 

public static void main(String[] args) {      

int count = 0; 

for(int x=1; x<5; x++) {      

for(int y=1; y<5; y++) {        

for(int z=1; z<5; z++) { 

if(x != y && y != z && x != z) {         

count ++; 

System.out.println(x*100 + y*10 + z );     

}       

 }       

}     

 } 

     System.out.println("共有" + count + "个三位数"); 

}

 

 

【程序12  题目:企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%20万到40万之间时,高于20万元的部分,可提成5%40万到60万之间时高于40万元的部分,可提成3%60万到100万之间时,高于60万元的部分,可提成1.5%,高于100万元时,超过100万元的部分按1%提成,从键盘输入当月利润,求应发放奖金总数?    

import java.util.*; 

public class lianxi12 { 

public static void main(String[] args) {      

double x = 0,y = 0; 

System.out.print("输入当月利润):");  

Scanner s = new Scanner(System.in);      

x = s.nextInt(); 

if(x > 0 && x <= 10) { 

y = x * 0.1;

} else if(x > 10 && x <= 20) {

y = 10 * 0.1 + (x - 10) * 0.075;

} else if(x > 20 && x <= 40) {

y = 10 * 0.1 + 10 * 0.075 + (x - 20) * 0.05;

} else if(x > 40 && x <= 60) {

y = 10 * 0.1 + 10 * 0.075 + 20 * 0.05 + (x - 40) * 0.03;

} else if(x > 60 && x <= 100) {

y = 20 * 0.175 + 20 * 0.05 + 20 * 0.03 + (x - 60) * 0.015;

} else if(x > 100) {

y = 20 * 0.175 + 40 * 0.08 + 40 * 0.015 + (x - 100) * 0.01;

}

System.out.println("应该提取的奖金是" + y + "");

}

}

 

【程序13  题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?    

public class lianxi13 { 

public static void main(String[] args) {     

 for(int x =1; x<100000; x++) {       

if(Math.sqrt(x+100) % 1 == 0) {        

if(Math.sqrt(x+168) % 1 == 0) { 

 System.out.println(x + "100是一个完全平方数,再加168又是一个完全平方数");   

}       

}     

}

the end

评论(0)