1、笔记扫描仪/*import java.util.Scanner;public class test2 public static void main(String args) Scanner in=new Scanner(System.in);System.out.print(“请输入您的姓名:“);String name=in.next();System.out.print(“请输入您的年龄:“);int age=in.nextInt();System.out.println(“姓名:“+name);System.out.println(“年龄:“+age);*/关系运算符/*import
2、java.util.Scanner;public class test2 public static void main(String args)int a = 2;int b = 2;boolean flog;flog=a=b;System.out.print(flog);*/else if 多重 if 结构/*import java.util.*;public class test2 public static void main(String args)Scanner input =new Scanner(System.in); System.out.print(“请输入你的 Java
3、成绩:“);int scoer= input.nextInt();if(scoer=90)System.out.println(“优秀“);else if(scoer=80)System.out.println(“良好“);else if(scoer=60)System.out.println(“中等“); else System.out.println(“差“);*/if 嵌套结构import java.util.*;public class test2public static void main(String args)Scanner in= new Scanner(System.in)
4、;System.out.print(“请问你的性别是?(男/女)“);String sex =in.next();if(sex.equals(“男“)System.out.print(“你的年龄是多少?“);int age=in.nextInt();if (age=18)System.out.print(“成年了“);else System.out.print(“未成年“);else System.out.print(“女“);switch 循环import java.util.*;public class test2public static void main(String args)Sc
5、anner in= new Scanner(System.in);System.out.print(“请输入你的名次:“);/*String sex =in.next();*/int mingci=in.nextInt();/* if(sex.equals(“男“)System.out.print(“你的年龄是多少?“);int age=in.nextInt();if (age=18)System.out.print(“成年了“);else System.out.print(“未成年“);else System.out.print(“女“);*/switch(mingci)case 1:Sys
6、tem.out.println(“出任武林盟主“);break;case 2:System.out.println(“出任武当掌门“);break;case 3:System.out.println(“出任峨眉掌门“);break;default:System.out.print(“逐出师门“);算数运算符等价于 Int c=a200?200:500;累加求和:package com.test;public class test public static void main(String args) int i = 1 ;int sum =0;while(iA)System.out.prin
7、tln(“大了“ );while(number!=A);System.out.println(“猜对了!电脑随机数为:“+A);平均分:package com.test;import java.util.Scanner;public class test public static void main(String args)Scanner in=new Scanner(System.in);int sum =0;for(int i=0;i5?“nt“:“t“),“);if(i0?-y*365+y/4-y+/100+bm-1:5+bm-1;u=bm-bm-1;if(y%40|y2)s+;if(
8、m=2)u+;catch(Exception E)u=i;if(u=i)System.out.println(i474?30:c+65;b+=c0)c=b=665?525:b=525?665:b=35?175:35;g.drawLine(225,c,355,b);b-=b=525?350:140;b=20;c=248;g.setFont(new Font(“,0,40);for(int i=0;i350?20:b+130;c+=b380?85:b+390;c+=bB+35y=yC+40y=yC-100break;/黑卒case 5:/红炮case 12:/黑炮case 0:/红車case 7:
9、/黑車 case 1:/红馬case 8:/黑馬case 2:/红相case 9:/黑象case 3:/紅士case 10:/黑士case 4:/紅帥case 11:/黑將if(x=ai.getX()remove(ai);z=32;repaint();else z=i;class m extends MouseAdapter/鼠标事件监听,继承鼠标点击事件监听public void mouseClicked(MouseEvent e) tryA=az.i;B=az.getX();C=az.getY();x=e.getX()-30;y=e.getY()-30;switch(A) /走棋規則設定c
10、ase 6:x=CB+35y=yC+40y=yC-100break;/黑卒case 5:/红炮case 12:/黑炮case 0:/红車case 7:/黑車 case 1:/红馬case 8:/黑馬case 2:/红相case 9:/黑象case 3:/紅士case 10:/黑士case 4:/紅帥case 11:/黑將 az.setBounds(x,y,60,60);z=32;repaint();catch(Exception c)class qz extends JButton/棋子函数Stringz=“車“,“馬“,“相“ ,“士“, “帥“ ,“炮“,“ 兵“,“ 車“,“馬“ ,“象
11、“, “士“,“將“ ,“炮“, “卒“ ;int i;qz(int x,int y) setBounds(x, y, 60, 60);/设置坐标和大小坐标setContentAreaFilled(false);/透明setBorderPainted(false);/消除按钮外接框public void paint(Graphics g)super.paint(g);g.setColor(Color.CYAN);g.fillOval(0, 0, 60, 60);if(i=0;i-)System.out.println(arri);数组复制import java.util.Scanner;import java.util.Arrays;public class test2 public static void main(String args) Scanner in = new Scanner(System.in);int arrA = 1, 2, 3, 4, 5, 6 ;int arrB = new intarrA.length;for (int i = 0; i arrA.length; i+) arrBi=arrAi;for(int i=0;iarrA.length;i+)System.out.print(arrBi);