语句"/>
Java的条件语句
判断分数级别
import java.util.Scanner;
public class TestIf04{public static void main(String[] args){//1.��������Scanner sc=new Scanner(System.in);System.out.print("�������Ա���֣�");//���жϼ���¼��������Dz���int���͵�if(sc.hasNextInt()==true){//��int�������ݣ�//�����int���͵����ݽ���int score =sc.nextInt();if(score>=0){String discount ="";//2.���ݻ����ж��ۿ�if(score>=8000){discount="0.6";}else if(score>=4000){discount="0.7";}else if(score>=2000){discount="0.8";}else {discount="0.9";}System.out.println("�û�Ա���ܵ��ۿ��ǣ�"+discount);}else{//score<0System.out.println("�Բ�����¼��Ļ����Ǹ���");}}else{//����int���͵�����System.out.print("��¼��Ļ��ֲ�������!");}}
}
小孩搬凳子
import java.util.Scanner;
public class TestIf06{public static void main(String[] args){//1、录入小朋友的年龄Scanner sc=new Scanner(System.in);System.out.println("请录入小朋友的年龄");int age=sc.nextInt();//根据年龄判断:if(age>=7){System.out.println("yes");}else if(age>=5){//录入小朋友的性别System.out.println("请录入小朋友的性别");int sex= sc.next();char sex=str.charAt(0);if(sex=='男'){//男生System.out.println("yes");System.out.println("no");}else{//女孩System.out.println("no");}}else{//age<5System.out.println("no");}}}
更多推荐
Java的条件语句
发布评论