1.输入商品单价,数量,求总价。活动8折后抹零,计算活动价。
输入付款金额,计算找零并输出
package work3;
import java.util.Scanner;
public class Exercise1 {
/**
* @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 number=input.nextInt();
double zongjia;
double huodongjia;
zongjia=price*number;
System.out.println("总价为"+zongjia);
huodongjia=price*number*0.8;
int b=(int)huodongjia;//将浮点型强制转化为整形
System.out.println("活动价为"+b);
System.out.println("请输入付款金额");
double payment=input.nextDouble();
double zhaoling;
zhaoling=payment-b;
System.out.println("找零数目为"+zhaoling);
}
}

2.输入一个三位数,求个位,十位和百位。
package work3;
import java.util.Scanner;
public class Exercise2 {
/**
* @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 gewei,shiwei,baiwei;
gewei=a%10;
shiwei=a%100/10;
baiwei=a/100%10;
System.out.println("个位为"+gewei+"\n十位为"+shiwei+"\n百位为"+baiwei);
}
}

3.输入大写字母,转成对应的小写字
package work3;
import java.util.Scanner;
public class Exercise3 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input=new Scanner(System.in);
System.out.println("请输入大写字母");
char ch=input.next().charAt(0);
ch=(char)(ch+32);
System.out.println("对应的小写字母为"+ch);
}
}

4.输入2个数,用三目运算符,输出较大数
package work3;
import java.util.Scanner;
public class Exercise4 {
/**
* @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 n=(a>b)?a:b;
System.out.println("大数为"+n);
}
}

浙公网安备 33010602011771号