Java第三次作业
1.输入商品单价,数量,求总价.活动八折后抹零,计算活动价.输入付款金额,计算找零并输出.
import java.util.Scanner; public class chap { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入单价"); double a=input.nextDouble(); System.out.println("请输入数量"); int b=input.nextInt(); double c,d; c=a*b; d=c*0.8; System.out.println("总价为"+c+"\t"+"折后价"+d); System.out.println("请输入付费钱数"); int e=input.nextInt(); System.out.println("付费"+e); System.out.println("找零"+(e-c)); } }
2.输入一个三位数,求个位,十位和百位.
import java.util.Scanner; public class chap { /** * @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(); System.out.println("个位为"+(x%10)); System.out.println("十位为"+(x/10%10)); System.out.println("百位为"+(x/100)); } }
3.输入大写字母,转成对应的小写字母.
import java.util.Scanner; public class chap { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入大写字母"); char a=input.next().charAt(0); System.out.println("对应的小写字母是"+(char)(a+32)); } }
4.输入2个数,用三目运算符,输出较大数
import java.util.Scanner; public class chap { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner input=new Scanner(System.in); System.out.println("请输入两个数"); int a=input.nextInt(); int b=input.nextInt(); int c; c=a>b?a:b; System.out.println("较大的数为"+c); } }