Java第三次作业

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

 

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("输入交换前a,b的值");
        int a=input.nextInt();
        int b=input.nextInt();
        int c;
        System.out.println("a="+a+"\t"+"b="+b+"\t");
        c=a;
        a=b;
        b=c;
        System.out.println("a="+a+"\t"+"b="+b+"\t");
    }

}

 

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

 

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

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

}

 


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

输入付款金额,计算找零并输出

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

    /**
     * @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;
     int discount=(int)(sum*0.8);
     System.out.println("输入付款金额");
      int fukuan=input.nextInt();
      double zhaoling=fukuan-sum;
      System.out.println("总价="+sum+"\t"+" 活动价="+discount+"\t"+" 付款"+fukuan+"元,"+" 找零"+zhaoling+"元"+"\t");
    }

}

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

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

    /**
     * @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 ge=num%10;
      System.out.println("个位是"+ge);
       int shi=num/10%10;
       System.out.println("十位是"+shi);
      int bai=num/100;
       System.out.println("百位是"+bai);
   
    }

}

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

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

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
     Scanner input=new Scanner(System.in);
     System.out.println("输入一个大写字母");
     String a=input.nextLine();
     char c;
     c=a.charAt(0);
     System.out.println((char)(c+32));
    }

}

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

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

    /**
     * @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 y=input.nextInt();
     int max=x>y?x:y;
     System.out.println("输出较大的数"+max);
    }

}

 

posted @ 2021-03-26 21:07  曲蔓特  阅读(45)  评论(0编辑  收藏  举报