java第三次作业

1.输入两个数,交换后输出

package Homework;
import java.util.Scanner;
public class test1 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        System.out.println("输入a");
        int a=input.nextInt();
        System.out.println("输入b");
        int b=input.nextInt();
        int   c=a;
        a=b;
        b=c;
        System.out.println("交换后a="+a+ " b是"+b);
    }

}

 

2.输入两个数,求平方和

package Homework;
import java.util.Scanner;
public class test02 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        System.out.println("输入a");
        int a=input.nextInt();
        System.out.println("输入b");
        int b=input.nextInt();
        int c=a*a+b*b;
        System.out.println("平方和="+c);
    }

}

 

 

 

3.输入商品总价,数量,求总价。活动八折后抹零,计算活动价。

package Homework;

import java.util.Scanner;

public class test3 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
   Scanner  input=new Scanner(System.in);
   System.out.println("请输入单价");
   double price=input.nextDouble();
   System.out.println("请输入数量");
   int num=input.nextInt();
   double sum=price*num;
   System.out.println("总价是"+sum);
   
    int zhehou = (int) (sum*0.8);
    System.out.println("折后抹零价是"+zhehou);
    System.out.println("input you pay");
    double pay = input.nextDouble();
    double zl = pay-zhehou;
    System.out.println("zhaoling:" +zl);
    }

}

 4.输入一个三位数,求个位,十位和百位。

 

import java.util.Scanner;


public class test4 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
     Scanner input = new Scanner(System.in);
     int num = input.nextInt();
     int ge = num % 10;
     int bai = num / 100;
     int shi = num / 10 % 10;
     System.out.println("ge:" +ge+"shi" +shi+"bai" +bai);
    }
    
}

5.输入大写字母,转成对应的小写的字母

 

package Homework;

import java.util.Scanner;

public class test5 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input = new Scanner(System.in);
        System.out.println("任意输入一个大写字母");
        char b=input.next().charAt(0);
        System.out.println("对应的小写字母是"+(char)(b+32));

    }

}

 

 

 

 

 

 

 

 

 

6.输入两个数,用三目运算符,输出较大数。

package Homework;

import java.util.Scanner;

public class test6 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
   Scanner input=new Scanner(System.in);
   System.out.println("请输入第一个数");
   int num1=input.nextInt();
   System.out.println("请输入第二个数");
   int num2=input.nextInt();
   
   
   int max=num1>num2?num1:num2;
   System.out.println("较大数是"+max);
    }

}

 

posted @ 2021-03-27 11:46  ·梓清  阅读(78)  评论(0编辑  收藏  举报