1.题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
public
class
TestTN {
public
static
void
main(String[] args) {
for
(
int
i=
1
; i<=
4
; i++){
for
(
int
j=
1
; j<=
4
; j++){
if
(j == i)
continue
;
for
(
int
k=
1
; k<=
4
; k++){
if
(k == j || k == i)
continue
;
System.out.print(i*
100
+ j*
10
+ k +
","
);
}
}
}
}
}
2.题目:企业发放的奖金根据利润提成。利润(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%提成,从键盘输入当月利润I,求应发放奖金总数? package
test50;
import
java.io.BufferedReader;
import
java.io.InputStreamReader;
/**
* @author VellBibi
*【程序12】 MoneyAward.java
*题目:企业发放的奖金根据利润提成。
*利润(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%提成,
*从键盘输入当月利润I,求应发放奖金总数?
*1.程序分析:请利用数轴来分界,定位。注意定义时需把奖金定义成长整型。
*/
public
class
MoneyAward {
public
static
double
sumMoneyAward(
double
i){
if
(i <=
10
){
return
i *
0.1
;
}
else
if
(i <
20
){
return
((i -
10
) *
0.075
+
1
);
}
else
if
(i <
40
){
return
(i -
20
) *
0.05
;
}
else
if
(i <
60
){
return
(i -
40
) *
0.03
;
}
else
if
(i <
100
){
return
(i -
60
) *
0.015
;
}
else
{
return
(i -
100
) *
0.001
;
}
}
public
static
void
main(String[] args) {
BufferedReader br =
new
BufferedReader(
new
InputStreamReader(System.in));
double
I =
0
;
try
{
System.out.println(
"请输入当月利润I:(单位:万)"
);
I = Integer.parseInt(br.readLine());
}
catch
(Exception e) {
e.printStackTrace();
}
System.out.println(
"奖金总数:"
+ sumMoneyAward(I) +
"万"
);
}
}
3.题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少? /**
* @author VellBibi
*【程序13】FindNumber.java
*题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
*1.程序分析:在10万以内判断,先将该数加上100后再开方,再将该数加上268后再开方,如果开方后的结果满足如下条件,即是结果。请看具体分析:
*/
public
class
FindNumber {
public
static
void
main(String[] args) {
for
(
int
i=
1
; i<
100000
; i++){
if
(Math.sqrt(i +
100
) %
1
==
0
&& Math.sqrt(i +
268
) %
1
==
0
){
System.out.println(i);
// break;
}
}
}
}
4.题目:输入某年某月某日,判断这一天是这一年的第几天?package test50;import java.io.BufferedReader;import java.io.InputStreamReader;/** * @author VellBibi *【程序14】 TestDay.java *题目:输入某年某月某日,判断这一天是这一年的第几天? *1.程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊情况,闰年且输入月份大于3时需考虑多加一天。 */public class TestDay { public static boolean isLeapYear(int y){ if((y%4 == 0 && y%100 != 100) || y%400 == 0) return true; else return false; } public static int sumDays(int y, int m, int d){ int[] MonthDays = {31,28,31,30,31,30,31,31,30,31,30,31}; if(isLeapYear(y)) MonthDays[1] = 29; int ans = 0; for(int i=0; i<m-1; i++){ ans = ans + MonthDays[i]; } return ans + d; } public static void main(String[] args) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String in = null; try { System.out.println("请输入年月日,例如:2014-01-01"); in = br.readLine(); } catch (Exception e) { System.out.println("格式错误"); } int y = Integer.parseInt(in.substring(0, in.indexOf('-'))); int m = Integer.parseInt(in.substring(in.indexOf('-') + 1, in.lastIndexOf('-'))); int d = Integer.parseInt(in.substring(in.lastIndexOf('-') + 1)); System.out.println(sumDays(y, m, d)); }}
5.题目:输入三个整数x,y,z,请把这三个数由小到大输出。package test50;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.ArrayList;import java.util.Collections;import java.util.Iterator;import java.util.List;/** * @author VellBibi * 题目:输入三个整数x,y,z,请把这三个数由小到大输出。 * 1.程序分析:舍近求远,练习容器,可以使用List容器很简单实现。 */public class Sort { public static List<Double> readDouble(String str, String sp){ List<Double> l = new ArrayList<Double>(); int j = 0; for(int i=0; i<str.length(); i++){ if(str.substring(i, i+1).equalsIgnoreCase(sp) ){ l.add(Double.parseDouble(str.substring(j, i))); j = i + 1; } } return l; } public static void main(String[] args) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); List<Double> l = null; try { System.out.println("输入数据,如:1,2,3,4,"); l = readDouble(br.readLine(), ","); } catch (IOException e) { e.printStackTrace(); } System.out.println(l.isEmpty()); Collections.sort(l); Iterator<Double> it = l.iterator(); while(it.hasNext()){ System.out.print(it.next() + " "); } }}
原标题:简单又有趣的java题
关键词:JAVA