第五周java作业

上机:

1.(1) package shd;

 

public class lj5921 {

 

/**

 * @param args

 */

public static void main(String[] args) {

// TODO Auto-generated method stub

int i = 1;

int sum=0;

while (i <= 100) {

if (i % 3== 0){

         sum+=i;

}

i++;}

System.out.println(sum);

}

 

}

 

 

(2) package shd;

 

public class lj5921 {

 

/**

 * @param args

 */

public static void main(String[] args) {

// TODO Auto-generated method stub

int i = 1;

int sum=0;

for(;i<=100;i++) {

if (i % 3== 0){

         sum+=i;

}

}

System.out.println(sum);

}

}

 

 

(3) package shd;

 

public class lj5921 {

 

/**

 * @param args

 */

public static void main(String[] args) {

// TODO Auto-generated method stub

int i = 1;

int sum=0;

do {

if (i % 3== 0){

         sum+=i;

}

i++;

} while(i<=100);

System.out.println(sum);

}

}

 

 

2. package shd;

 

public class lj5921 {

 

/**

 * @param args

 */

public static void main(String[] args) {

// TODO Auto-generated method stub

int i=1;

 while(i<=9){

 if(i!=5){

              

System.out.println(i);}

i++;

}

 

 

}

}

 

 

 

3. package shd;

import java.util.Scanner;

public class lj5921 {

 

/**

 * @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;

int y=1;

while(y<=x){

sum=sum*y;

y++;

}

     System.out.println("sum="+sum);

}

}

 

 

 

4. package shd;

import java.util.Scanner;

public class lj5921 {

 

/**

 * @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();

   if(x<0||x>=100){

   System.out.println("错误,请重新输入");

   }else{

     System.out.println("正确");}

}

}

 

 

 

5. package shd;

 

public class lj5921 {

 

/**

 * @param args

 */

public static void main(String[] args) {

// TODO Auto-generated method stub

double y=30000,x=1,sum=30000;

while(x<=10){

sum=sum+y;

y=y+(y*0.06);

x++;

}

System.out.println("10年的工资是"+y);

System.out.println("总工资是"+sum);

}

}

 

 

 

 

 

作业:1. package shd;

 

public class lj5921 {

 

/**

 * @param args

 */

public static void main(String[] args) {

// TODO Auto-generated method stub

int i = 100;

while (i <= 999) {

int a = i % 10;

int b = i / 10 % 10;

int c = i / 100;

 

if (a * a * a + b * b * b + c * c * c == i)

System.out.println(i);

i++;

}

}

}

 

 2.

package Home;

import java.util.Scanner;

public class Home {

    /**
     * @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 sum=0;
        int days;
        for (; month-1 >0 ; month--) {
            if(month-1==1||month-1==3||month-1==5||month-1==7||month-1==8||month-1==10){
                days=31;
            }else if(month-1==4||month-1==6|month-1==9||month-1==11){
                days=30;
            }else if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0
                    && month-1 == 2) {
                System.out.println("该年为闰年");
                days = 29;
            } else {
                days = 28;
            }
            sum=sum+days;
        }
        sum=sum+day;
        System.out.println("今天是"+year+"年的第"+sum+"天");
    }

}
复制代码

 

 

3.

package Home;

import java.util.Scanner;

public class Home {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        System.out.println("请输入一个四位整数");
        int num=input.nextInt();
        int[ ] a=new int[4];
        for (int i = 0; i < 4; i++) {
            a[i]=num%10;
            num=num/10;
        }
        System.out.println(a[0]*1000+a[1]*100+a[2]*10+a[3]);
    }

}

 

 

复制代码

posted on 2021-04-04 23:01  觊·觎  阅读(41)  评论(0编辑  收藏  举报

导航