当前位置: 首页 > news >正文

青岛做优化网站哪家好宁波seo教程

青岛做优化网站哪家好,宁波seo教程,编程一小时网站,vs2008不能新建网站📒博客首页:Sonesang的博客 🎉欢迎关注🔎点赞👍收藏⭐️留言📝 ❤️ :热爱Java与算法学习,期待一起交流! 🙏作者水平很有限,如果发现错误&#xf…

📒博客首页:Sonesang的博客

🎉欢迎关注🔎点赞👍收藏⭐️留言📝

❤️ :热爱Java与算法学习,期待一起交流!

🙏作者水平很有限,如果发现错误,求告知,多谢!

🌺有问题可私信交流!!!


一、if 语句

1. 基本if-else语句

当条件成立时,执行某些语句;否则执行另一些语句。

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int a = sc.nextInt();if (a > 5) {System.out.printf("%d is big!\n", a);System.out.printf("%d + 1 = %d\n", a, a + 1);} else {System.out.printf("%d is small!\n", a);System.out.printf("%d - 1 = %d\n", a, a - 1);}}
}

else 语句可以省略:

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int a = sc.nextInt();if (a > 5) {System.out.printf("%d is big!\n", a);System.out.printf("%d + 1 = %d\n", a, a + 1);}}
}

当只有一条语句时,大括号可以省略:

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int a = sc.nextInt();if (a > 5)System.out.printf("%d is big!\n", a);elseSystem.out.printf("%d is small!\n", a);}
}

练习:输入一个整数,输出这个数的绝对值。

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int x = sc.nextInt();if (x > 0)System.out.println(x);elseSystem.out.println(-x);}
}

练习:输入两个整数,输出两个数中较大的那个。

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int a = sc.nextInt(), b = sc.nextInt();if (a > b)System.out.println(a);elseSystem.out.println(b);}
}

if-else语句内部也可以是if-else语句。

练习:输入三个整数,输出三个数中最大的那个。

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();if (a > b) {if (a > c)System.out.println(a);elseSystem.out.println(c);} else {if (b > c)System.out.println(b);elseSystem.out.println(c);}}
}

2. 常用比较运算符

(1) 大于 >
(2) 小于 <
(3) 大于等于 >=
(4) 小于等于 <=
(5) 等于 ==
(6) 不等于 !=

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int a = sc.nextInt(), b = sc.nextInt();if (a > b) System.out.printf("%d > %d\n", a, b);if (a >= b) System.out.printf("%d >= %d\n", a, b);if (a < b) System.out.printf("%d < %d\n", a, b);if (a <= b) System.out.printf("%d <= %d\n", a, b);if (a == b) System.out.printf("%d == %d\n", a, b);if (a != b) System.out.printf("%d != %d\n", a, b);}
}

3. if-else连写

输入一个0到100之间的分数,
如果大于等于85,输出A;
如果大于等于70并且小于85,输出B;
如果大于等于60并且小于70,输出C;
如果小于60,输出 D;

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int s = sc.nextInt();if (s >= 85) {System.out.println("A");} else if (s >= 70) {System.out.println("B");} else if (s >= 60) {System.out.println("C");} else {System.out.println("D");}}
}

练习:

1.判断闰年。闰年有两种情况:

(1) 能被100整除时,必须能被400整除;
(2) 不能被100整除时,被4整除即可。
输入一个年份,如果是闰年输出yes,否则输出no。

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int year = sc.nextInt();if (year % 100 == 0) {if (year % 400 == 0)System.out.println("yes");elseSystem.out.println("no");} else {if (year % 4 == 0)System.out.println("yes");elseSystem.out.println("no");}}
}

二、条件表达式

(1) 与 &&
(2) 或 ||
(3) 非 !

例题:输入三个数,输出三个数中的最大值。

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();if (a >= b && a >= c)System.out.println(a);else if (b >= a && b >= c)System.out.println(b);elseSystem.out.println(c);}
}

练习:用一条if语句,判断闰年。

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int year = sc.nextInt();if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)System.out.println("yes");elseSystem.out.println("no");}
}

三、switch 语句

注意: swtich语句中如果不加break语句,则从上到下匹配到第一个case后,会顺次执行后面每个case中的语句。

import java.util.Scanner;public class Main {public static void main(String[] args) {Scanner sc = new Scanner(System.in);int day = sc.nextInt();String name;switch(day) {case 1:name = "Monday";break;case 2:name = "Tuesday";break;case 3:name = "Wednesday";break;case 4:name = "Thursday";break;case 5:name = "Friday";break;case 6:name = "Saturday";break;case 7:name = "Sunday";break;default:name = "not valid";}System.out.println(name);}
}
http://www.15wanjia.com/news/178273.html

相关文章:

  • vs做网站创建项目时选哪个网页设计尺寸多大
  • 纯静态做企业网站做个网站
  • 网站优化推广多少钱综合门户类网站有哪些
  • 金堂做网站的公司郯城网站建设
  • 中国建设招标网 官方网站下载青岛房产网链家
  • 5118网站查询做网站广告的点
  • 灰色网站怎么做seo地方门户模板
  • 台州自助建站公司wordpress 分类文章插件
  • 网站超链接怎么做 wordasp企业网站开发技术
  • 在网站挂广告一个月多少钱营销展示型网站建设价格
  • wps可以做网站吗建设工程公司起名
  • 在线做h5 的网站只做网站应该找谁
  • 网站建设岗位将来有什么发展北京云建站模板
  • 百度上怎么制作自己的网站站长之家排名查询
  • 个人网站备案 网站名称百度推广有哪些形式
  • 本地推广找哪些网站创网
  • 泉州建设人才网站百度下载安装2021最新版
  • 做网站主机要选好公关公司职位
  • 北京建设制作网站简述seo的概念
  • 给彩票网站做代理违法吗网页版微信怎么删除聊天记录
  • 河池网站建设网站开发会什么软件
  • 大创项目做英语网站wordpress 给标签加id
  • 网站建设 后台南昌大型网站制作
  • 企业做网站的公司有哪些wap网站分享到微信
  • 巫溪集团网站建设零食网站源码
  • 机械类产品网站做优化保定建网站需要多少钱
  • 用ps制作网站首页wordpress发红包插件
  • 什么网站可以做医疗设备的移动宽带怎么网上续费
  • 外贸网站友情链接北京网站制作策划
  • 桂林微信网站开发网站页面在线设计