第三周
输入商品单价,数量,求总价。活动8折后抹零,计算活动价。
输入付款金额,计算找零并输出
package Class;
import java.util.Scanner;
public class Class1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
System.out.println("输入商品单价");
int danjia=input.nextInt();
System.out.println("输入商品数量");
int shuliang=input.nextInt();
int sum=danjia*shuliang;
System.out.println("商品总价是"+sum);
int huodongjia=sum*8/10;
System.out.println("商品活动价是"+huodongjia);
System.out.println("输入付款金额");
int fukuanjine=input.nextInt();
int zhaoling=fukuanjine-huodongjia;
System.out.println("找零"+zhaoling);
}
- }
2.输入一个三位数,求个位,十位和百位。
package Class;
import java.util.Scanner;
public class Class1 {
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,c,d;
b=a/100;
System.out.println("百位上的数是"+b);
c=a/10%10;
System.out.println("十位上的数是"+c);
d=a%10;
System.out.println("个位上的数是"+d);
}
}
3.输入大写字母,转成对应的小写字母
package Class;
import java.util.Scanner;
public class Class1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("请输入字符串:");
String character = sc.nextLine();
char[] arr=character.toCharArray();
for (int i = 0; i < arr.length; i++) {
if ((int)arr[i] >= 65 && (int)arr[i] <= 90) {
arr[i] += 32;
} else if ((int)arr[i] >= 97 && (int)arr[i] <= 122) {
arr[i] -= 32;
}
}
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+" ");
}
}
}
4.输入2个数,用三目运算符,输出较大数
package Class;
import java.util.Scanner;
public class Class1 {
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 z;
z=a>b?a:b;
System.out.println("最大值为"+z);
}
}