Java的条件语句

编程入门 行业动态 更新时间:2024-10-23 15:33:33

Java的条件<a href=https://www.elefans.com/category/jswz/34/1770772.html style=语句"/>

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的条件语句

本文发布于:2023-11-17 12:52:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1642514.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:语句   条件   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!