1.包

2.运算符

public class Operator {public static void main(String[] args) {int a = 5;System.out.println("a = " + a);//a = -a; //+   -System.out.println("a = " + a);//+ 字符串链接System.out.println("影分身" + "软件开发");System.out.println(3 + 5 + "软件开发" + 6 + 8);double b = a / 2;System.out.println("a / 2 = " + (a / 2));System.out.println("b = " + b);int weith = 10;int height = 6;double area =  1.0 / 2 * weith * height;System.out.println("area = " + area);int c = a % 3;//取余数System.out.println("c = " + c);//int d = c++;//  c++  c = c + 1; 先赋值 后自增int d = ++c;//先自增 后赋值System.out.println("d = " + d);System.out.println("c = " + c);//赋值  int e = 10; //-=  *= /= %=e += 1;// e = e + 1;System.out.println("e = " + e);//比较 > >=  5 >= 5  5 > 5  < <=  ==boolean isEquals = (1 == 1);System.out.println("isEquals = " + isEquals);int year = 2012;boolean isLeap = (year % 4 == 0 && year % 100 != 0 || year % 400 == 0); System.out.println(year +" 是否是闰年 " + isLeap);System.out.println("1 != 2 ? " + (1 != 2));//逻辑boolean isTrue = false;System.out.println("isTrue ? " + isTrue);System.out.println("!isTrue ? " + !isTrue);System.out.println("true || false ? " + (true || false));//或运算System.out.println("true && false ? " + (true && false));//与运算int score = 85;//score > 60  及格   > 70  良   > 85 优秀// javase > 60 && oracle > 70  && xml > 70 // javase > 60 || oracle > 60  || xml > 60 int move = 16;System.out.println("move = " + (move >> 3));//100   10System.out.println("move = " + (move << 1));}}

3.选择语句

import java.util.Random;//导入类
public class IfDemo {public static void main(String[] args) {Random ran = new Random();//new 创建对象int score = ran.nextInt(101);//ran.nextInt(41) + 60;//随机数 0 ~ 100System.out.println("score = " +  score);/*if(score > 60) {//满足条件执行System.out.println("============");System.out.println("   及格了..");System.out.println("============");}*///if的第二种形式/*if(score > 60) {//满足条件执行  System.out.println("============");System.out.println("   及格了..");System.out.println("============");} else {  //不满足条件执行System.out.println("============");System.out.println("   很遗憾..");System.out.println("============");}*///多分支  匹配其中一个条件/*if( score >= 90) {System.out.println("成绩: A");} else if ( score >= 80 /*&& score < 90) {System.out.println("成绩: B");} else if ( score >= 60 /*&& score < 80) {System.out.println("成绩: C");} else {System.out.println("成绩: D");}*/switch(score / 10) {//如果匹配 下面代码执行case 10: //System.out.println("成绩: A");break;case 9: System.out.println("成绩: A");break;case 8: System.out.println("成绩: B");break;case 7: System.out.println("成绩: C");break;case 6: System.out.println("成绩: D");break;default : System.out.println("成绩: 不及格");}//三目运算符boolean isPass = ( score > 60 ? true : false);System.out.println("成绩 === " + isPass);String passed = score > 60 ? "及格" : "挂了";System.out.println("成绩 ==== " + passed);}}

4.while循环

import java.util.Random;
public class LoopDemo {public static void main(String[] args) {int i = 0;//计数器//循环  不满足条件不执行   可能执行0次while( i < 10 ){     System.out.println( i + " Hello World!...");//执行代码i++;//运行时 i值每次发生改变 i = 10}System.out.println( "i = " + i );i = 0; // 0  9do{//先执行 后判断  至少执行一次System.out.println( i + " 快乐!...");i++;}while (i < 10);   int a = ran.nextInt(101);System.out.println( "a = " + a );int i = 2;while( i < a) {//67if( a % i == 0) {break;//跳出循环}i++;}System.out.println( "i = " + i );if(i >= a)//正常退出循环System.out.println( a +"是素数");elseSystem.out.println( a +"不是素数");}}

5.for循环

import java.util.Random;
public class LoopDemo2 {public static void main(String[] args) {int k = 10; //方法中的变量 作用域 在方法中使用//i 局部变量for(int i = 0;i < 10 ; i++ ) {//三条语句System.out.println( i + " Hello World!...");}//循环嵌套/*for(int i = 0; i < 5; i++) {//k = k + i;for(int j = 0; j < 3; j++) {System.out.print(" * ");}System.out.print("\n");//输出换行}*/for(int i = 1; i < 6; i++) {for(int j = 1; j <= i; j++) {System.out.print(j + " * " + i + " = "+ i * j + "  ");}System.out.print("\n");}int sum = 0;int i;for(i = 1; i < 200; i++) {sum += i;if(sum >= 200){break;}}System.out.println("sum = " + sum);System.out.println("i = " + i);}}

6.标记循环

import java.util.Random;
public class LoopDemo3 {public static void main(String[] args) {int sum = 0;int i,k = -1;loopi: for(i = 1; i < 200; i++) {for(int j = 1; j < 200; j++) {sum += j;if(sum >= 200){ k = j;break loopi;//指定跳出位置}}System.out.println("k = " + k);System.out.println("i = " + i);}System.out.println("sum = " + sum);System.out.println("k = " + k);for(int a = 1; a < 101; a++ ) {if( a % 3 != 0){//不能被3整除 continue;//结束本次后面代码执行}System.out.print( a + "\t");}}}

7.双循环

public class LoopDemo4 {public static void main(String[] args) {int sum = 0;for(int i = 1; i < 11; i++) {//控制的是行for(int j = 1; j <= i; j++) {//控制的是列System.out.print(" * ");/**/if(j > 5){ //1 2 3 4 5 6   7 8 9 10           break;//跳出内层循环}  }System.out.println();}}}

转载于:https://www.cnblogs.com/feilongblog/p/4656475.html

java新手笔记3 运算符循环相关推荐

  1. Java新手上路--算数运算符

    运算符:用于执行程序代码运算,会针对一个以上操作数项目来进行运算的符号.例如: + - 表达式:用运算符串联起来的式子.例如: 20+5 四则运算 首先说一下四则运算的代码运算,包括常量和变量的 + ...

  2. java新手笔记1 Hello World!

    //Hello.java文件 //类声明 public class Hello{//声明方法 main程序入口public static void main (String[] args) {Syst ...

  3. java新手笔记16 面积

    1.图形类 package com.yfs.javase;public class Shape {//计算面积方法public double getArea() {System.out.println ...

  4. Java 新手笔记(一)

    首先安装Java环境,编译器和解释器. 一 安装Java SE(Java标准平台) JDK主要内容如下: 二 系统环境配置 三 查看是否配置正确 一 安装Java SE(Java标准平台) 1.最新版 ...

  5. java新手笔记21 接口

    1.接口 package com.yfs.javase;public interface IDemo1 {//interface 接口public /*abstract*/ void method1( ...

  6. java学习笔记2(datawhale教程):运算符和表达式、流程控制、数组

    java学习笔记2(datawhale教程):运算符和表达式.流程控制.数组 文章目录 java学习笔记2(datawhale教程):运算符和表达式.流程控制.数组 一.运算符和表达式 1.数学函数与 ...

  7. Java基础知识 变量 基本类型 类型转换 标识符 关键字 运算符 循环 分支结构 JVM

    标题JVM **java语言是跨平台的,之所以跨平台是因为在不同的系统中安装不同的JVM这是Java跨平台的前提** 2.JDK:开发工具包-开发必须安装 JRE:运行时环境 JVM:Java虚拟机, ...

  8. Java快速入门学习笔记6 | Java语言中的for循环语句

    有人相爱,有人夜里开车看海,有人却连LeetCode第一题都解不出来!虽然之前系统地学习过java课程,但是到现在一年多没有碰过Java的代码,遇到LeetCode不知是喜是悲,思来想去,然后清空自己 ...

  9. Java快速入门学习笔记5 | Java语言中的while循环语句

    有人相爱,有人夜里开车看海,有人却连LeetCode第一题都解不出来!虽然之前系统地学习过java课程,但是到现在一年多没有碰过Java的代码,遇到LeetCode不知是喜是悲,思来想去,然后清空自己 ...

最新文章

  1. R语言paste函数、paste0函数将多个输入组合成字符串实战
  2. 智能家居正是扎根好时节 蓄积且待春雨
  3. 如何实现分享网站文章到微信朋友圈时显示指定缩略图或LOGO
  4. linux 产生0~9内的随机数
  5. 物理化学 界面现象
  6. 查找表存在于那些proc中
  7. 《网易编程题》分苹果
  8. 获取android手机的屏幕分辨率 android开发
  9. 通过源码将git升级到最新版
  10. 机器学习笔记(了解)
  11. 知识库如何跟其他业务系统结合
  12. 使用阿里云对象存储OSS收藏老婆新垣结衣日常照
  13. 腾讯、网易回应被约谈:严格落实未成年人防沉迷规定
  14. 让大家信任自己,做个行为和语言上都没黑盒子的技术人员(转)
  15. $ is not defined与SpringMVC访问静态资源
  16. 回顾:饶毅教授的一次采访
  17. 浏览器对象模型(Browser Object Model)
  18. 去掉桌面计算机快捷方式,电脑小技巧!去掉桌面快捷方式小箭头图标
  19. kitti点云地图拼接
  20. Received status code 409 from server: Conflict

热门文章

  1. Android WebView 调起H5支付,提示商家参数格式有误
  2. flutter 底部动画导航栏
  3. 进程的内存空间相互隔离
  4. 使用Notepad++自动排版代码
  5. KindEditor在eclipse里的配置方法
  6. python 循环内部添加多个条件判断会出现越界
  7. php 使用fseek指针读取大文件日志
  8. phpexcel导出后乱码或者是打不开文件必须修复的问题
  9. Android 5.0新特性
  10. iphone怎么检测屏幕是否被点亮 (用UIApplication的Delegate)