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