第五周
1.
package Class;
import java.util.Scanner;
public class Class1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("请输入一个数");
int x = input.nextInt();
int sum = 0;
for (int i = 1; i < x; i++) {
if (i%3 == 0) {
sum=sum+i;
}
}
System.out.println("0到100所有能被3整除的数之和为:"+sum);
}
}
package Class;
import java.util.Scanner;
public class Class1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("请输入一个数");
int x = input.nextInt();
int sum = 0;
int i = 1;
while(i<x){
if (i%3==0) {
sum=sum+i;
}
i++;
}
System.out.println("0到100所有能被3整除的数之和为:"+sum);
}
}
package Class;
import java.util.Scanner;
public class Class1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("请输入一个数");
int x = input.nextInt();
int sum = 0;
int i = 1;
do{
if (i%3==0) {
sum=sum+i;
}
i++;
} while(i<x);
System.out.println("0到100所有能被3整除的数之和为:"+sum);
}
}
2.
package Class;
import java.util.Scanner;
public class Class1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int i;
for(i=1;i<10;i++){
if(i==5){
}else{
System.out.println(i);
}
}
}
}
3.
package Class;
import java.util.Scanner;
public class Class1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("请输入一个数");
int x= input.nextInt();
int sum = 1;
for (int i = 1; i<=x; i++) {
sum=sum*i;
}
System.out.println("该数的阶乘为"+sum);
}
}
4.
package Class;
import java.util.Scanner;
public class Class1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("请输入一个数");
int x= input.nextInt();
while (true) {
if(x<0||x>100){
System.out.println("输入错误,重新输入");
x = input.nextInt();
}
else{
System.out.println("输入合法");
break;
}
}
}
}
5.
package Class;
import java.util.Scanner;
public class Class1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("请输入一个数");
int x= input.nextInt();
int sum = x;
for (int i = 1; i < 11; i++) {
x=(int) (x+x*0.06);
sum=sum+x;
}
System.out.println("该员工10年后的年薪为:"+x+"该员工未来10年的总收入为:"+sum);
}
}
课后作业
1.
package Class;
import java.util.Scanner;
public class Class1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
for (int i = 100; i < 1000; i++) {
int a = i%10;
int b = i/10%10;
int c = i/100;
if (i==a*a*a+b*b*b+c*c*c) {
System.out.println("该数是水仙花数:"+i);
}
}
}
}
2.
package Class;
import java.util.Scanner;
public class Class1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("请输入年");
int year= input.nextInt();
System.out.println("请输入月");
int month= input.nextInt();
System.out.println("请输入日");
int day= input.nextInt();
int days,sum=0;
for (int i = 1; i < month; i++) {
if(i==1||i==3||i==5||i==7||i==8||i==10||i==12){
days=31;
sum=sum+days;
}
if (i==2) {
if (i%4==0&&i%100!=0||i%400==0) {
days=29;
sum=sum+i;
}
else{
days=28;
sum=sum+i;
}
}
if (i==4||i==6||i==9||i==11) {
days=30;
sum=sum+i;
}
}
sum=sum+day;
System.out.println("该天是今年的"+sum+"天");
}
}
3.
package Class;
import java.util.Scanner;
public class Class1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
System.out.println("请输入一个数");
int x= input.nextInt();
int a = x%10;
int b = x/10%10;
int c = x/100%10;
int d = x/1000;
System.out.println("改变后的数为:"+a+""+b+""+c+""+d);
}
}