码迷,mamicode.com
首页 > 其他好文 > 详细

程序流程

时间:2015-10-08 09:04:06      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

if语句和逻辑运算符的使用

package computerArea;
import java.util.Scanner;
public class ComputerArea {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个数");
        int num = sc.nextInt();
        if(num % 5 == 0 && num % 6 == 0){
            System.out.println(num+"能被5和6整除。");
        }
        else if(num % 5 == 0 || num % 6 == 0){
            System.out.println(num+"能被5或6整除");
        }
        else if(num % 5 == 0 ^ num % 6 == 0){
            System.out.println(num+"能只被5或者只被6整除");
        }
        else
            System.out.println(num+"不能被5和6中任意一个数整除");
    }
}
      

 判断闰年

package computerArea;
import java.util.Scanner;
public class ComputerArea {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入年份:");
        int year = sc.nextInt();
        if((year % 4 == 0 && year % 100 == 0) || year % 400 == 0){
            System.out.println(year+"年是闰年");
        }
        else{
            System.out.println(year+"年不是闰年");
        }
    }
}
      

 if和String

package computerArea;
import java.util.Scanner;
public class ComputerArea {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您的成绩");
        double score = sc.nextDouble();
        String grade = "";
        if(score > 100 || score < 0){
            System.out.println("您输入的成绩不在合法范围");
            System.exit(0);
        }else if(score >= 90){
            grade = "优秀";
        }else if(score >= 80){
            grade = "良好";
        }else if(score >= 70){
            grade = "中等";
        }else if(score >= 60){
            grade = "及格";
        }else
            grade = "不及格";
        System.out.println("你的成绩为"+grade);
    }
}
      

 

程序流程

标签:

原文地址:http://www.cnblogs.com/rain-1/p/4859991.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!