java中输入输出语句_手打的笔记,java语法中的输入输出,语句,及注释。

手打的笔记:

() 内的则为注意事项或者提示

public static void main (String[] args) ******(用一个方法)****

{

int i = 10;

int j =20;

System.out.println(i == j);

与 并且关系:

System.out.println(true & true);

System.out.println(true & false);

System.out.println(false & true);

System.out.println(false & false);

System.out.println(i >0 && j>0);

或 或者关系:

System.out.println(true || true); (短路写法,只要前面对了,就都对了) (与并且相反)

非:

System.out.println(!(i < 0));

字节有八位

00000010

System.out.println(2 << 2); (00001000) 左移几位取决于后一位

3 2 = 12 3和2之间放什么符号 等式成立

左移运算规律:

x << y = x * 2的y次方

右移与左移相反

三元运算符:(不能单独存在,赋值或者输出)(可以套着写)

System.out.println(i>0 ? "i大于0" : "i小于等于0"); (类似if else 变形)

String str ="";

if(j>10)

{

str = "j大于10";

}

else

{

str = "j不大于10";

}

str = j >10 ? "j大于10" :"j不大于10";

System.out.println(str);

通过控制台手动输入:

System.in 输入流

System.out 输出流

Scanner sc =new Scanner(System.in); (实例化输入扫描器)

System.out.print("请输入名称:");

String strin = sc.nextLine(); (等待输入)

System.out.println("你输入的名称是:"+ strin); (输出接受的)

加法计算器: (其他的计算类型随意)

System.out.print("请输入第一个数字:");

long a =sc.nextLong();

System.out.print("请输入第二个数字:");

long b =sc.nextLong();

System.out.println(a+b);

分支语句:

int i =10;

if(i>0)

{

System.out.println("条件成立")

}

else

{

System.out.println("条件不成立")

}

if(i>0)System.out.println("i>0"); (简便写法)

if(i>0)

{

System.out.println("条件成立")

}

else if( i>5 )

{

System.out.println("条件不成立")

}

else

{

}

switch语句: (支持类型:int byte char short 枚举 字符串)

switch(i)

{

case1: (case后面必须为常量)

System.out.println("1");

break;

case2:

System.out.println("4");

break;

case3:

System.out.println("6");

break;

default:

System.out.println("123");

}

循环:

i=10;

while(i>0)

{

System.out.println("i ="+i);

i--;

}

do

{

System.out.println("i ="+i);

i--;

}

while(i>0);

for(i=0;i<10;i++)

{

System.out.println("i ="+i);

if(i==2)

{

continue; (跳过 执行后面的)

}

if(i==5)

{

break;

}

}

}

5588d0997bf8563344da515b6553b2ea.png

a4fac79b84c0113f9a6d068a32236bab.png

badb8a9f54a50ea2fabb96d01b0b9dde.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值