JAVA第三周作业0319
作业
1.输入商品单价,数量,求总价。活动8折后抹零,计算活动价。
输入付款金额,计算找零并输出
1 package homwork; 2 3 import java.util.Scanner; 4 5 public class Exe3_1 { 6 7 /** 8 * @param args 9 */ 10 public static void main(String[] args) { 11 // 1.输入商品单价,数量,求总价。活动8折后抹零,计算活动价。输入付款金额,计算找零并输出 12 Scanner input = new Scanner(System.in); 13 double ubitPrice ; //ubitPrice 单价 14 double amount ; // amount 数量、重量 15 double totalPrices ; //totalPrices 总价 16 double discountPrice ; //discountPrice 折扣价格 17 double receipt ; //receipt 收款 18 double change ; //change 找零 19 System.out.print("请输入商品单价:"); 20 ubitPrice = input.nextDouble() ; 21 System.out.print("请输入商品数量:"); 22 amount = input.nextDouble() ; 23 totalPrices = ubitPrice * amount ; 24 System.out.print("商品总价:" + totalPrices + "元"); System.out.println(); 25 discountPrice = (int) (totalPrices * 0.8) ; 26 System.out.println("8折抹零:" + discountPrice + "元"); 27 System.out.print("请输入收款金额:"); 28 receipt = input.nextDouble(); 29 change = receipt - discountPrice ; 30 System.out.println("找零:" + change + "元"); 31 32 } 33 34 }
package text; import java.util.Scanner; public class Text { public static void main(String[] args) { Scanner input = new Scanner(System.in); double danj ,shul ,zongj ,zhej ,shouk ,zhaol; // 单价 数量 总价 折价 收款 找零 System.out.println("请输入商品单价:"); danj = input.nextDouble(); System.out.println("请输入商品重量/数量:"); shul = input.nextDouble(); zongj = danj + shul; System.out.println("商品总价:"+zongj); zhej = zongj *0.8; System.out.println("商品8.0折后价格:"+String.format("%.2f", zhej)); // String.format("%.2f", f) 保留两位小数 System.out.println("请输入收款金额:"); shouk = input.nextDouble(); zhaol = shouk -zhej; System.out.println("找零 :"+ zhaol +"元"); } }
2.输入一个三位数,求个位,十位和百位。
1 package homwork; 2 3 import java.util.Scanner; 4 5 public class Exe3_2 { 6 public static void main(String[] args) { 7 //2.输入一个三位数,求个位,十位和百位。 8 Scanner input = new Scanner(System.in); 9 System.out.println("请输入一个三位数:"); 10 int num = input.nextInt(); 11 int ge = num % 10; 12 int shi = num % 100 / 10; 13 int bai = num % 1000 / 100; 14 System.out.println(num + ":"); 15 System.out.println("百位是" + bai); 16 System.out.println("十位是" + shi); 17 System.out.println("个位是" + ge); 18 } 19 20 }
3.输入大写字母,转成对应的小写字母
1 package homwork; 2 3 import java.util.Scanner; 4 5 public class Exe3_3 { 6 public static void main(String[] args) { 7 //3.输入大写字母,转成对应的小写字母 8 Scanner input = new Scanner(System.in); 9 System.out.println("请输入一个大写字母:"); 10 char D = input.next().charAt(0); 11 System.out.print(D + "的小写是:"); 12 char x = (char)(D + 32); 13 System.out.println(x); 14 } 15 16 }
4.输入2个数,用三目运算符,输出较大数
1 package homwork; 2 3 import java.util.Scanner; 4 5 public class Exe3_4 { 6 public static void main(String[] args) { 7 //4.输入2个数,用三目运算符,输出较大数 8 Scanner input = new Scanner(System.in); 9 double a , b ; 10 System.out.println("请输入两个数:"); 11 System.out.print("a="); 12 a = input.nextDouble(); 13 System.out.print("b="); 14 b = input.nextDouble(); 15 System.out.println("max=" + (a>b?a:b)); 16 } 17 }