首页
关于
友链
Search
1
java project 客户管理信息软件
149 阅读
2
java学习笔记10
135 阅读
3
java学习笔记12
129 阅读
4
java学习笔记1
122 阅读
5
java学习笔记9
120 阅读
默认分类
程序设计
java
vue前端
java学习笔记
java练习
java工程
登录
Search
标签搜索
java
java基础
学习笔记
练习
类
java进阶
数组
循环
vue
工程
helloworld
注释
关键字
变量
基本数据类型
选择
String
进制
运算符
Scanner
bandao
累计撰写
19
篇文章
累计收到
1
条评论
首页
栏目
默认分类
程序设计
java
vue前端
java学习笔记
java练习
java工程
页面
关于
友链
搜索到
3
篇与
的结果
2021-12-13
java练习3
用栈进行括号匹配/** * @program: exercise * @description: 用栈进行括号匹配 * @author: yuuko * @create: 2021-12-12 15:42 **/ import java.util.Scanner; import java.util.Stack; public class KuoHao { public static void main(String[] args) { Scanner input=new Scanner(System.in); String s=input.next(); System.out.println(solution(s)); } public static boolean solution(String s){ Stack<Character> stack1=new Stack<>(); char currentCorrectChar; for(int i=0;i<s.length();i++) { switch (s.charAt(i)) { case '(': stack1.push(')'); break; case '[': stack1.push(']'); break; case '{': stack1.push('}'); break; default: if(stack1.isEmpty()) return false; else currentCorrectChar = stack1.pop(); if (currentCorrectChar != s.charAt(i)) return false; } } if(!stack1.isEmpty()) return false; return true; } }自定义栈进行括号匹配/** * @program: exercise * @description: 自己定义的栈 * @author: yuuko * @create: 2021-12-12 15:49 **/ public class myCharStack { private myCharStack header; private myCharStack next=null; private char content; myCharStack(){ this.header=this; } myCharStack(char content){ this.content=content; } public void push(char content){ myCharStack stack1=new myCharStack(content); stack1.next=this.header.next; this.header.next=stack1; } public char pop(){ if(this.header.next==null){ System.out.println("EmptyStackException here"); return 'X'; } char popContent=this.header.next.content; this.header.next=this.header.next.next; return popContent; } public boolean isEmpty(){ return this.header.next == null; } }/** * @program: exercise * @description: * @author: kkx * @create: 2021-12-12 15:57 **/ import java.util.Scanner; public class myKuoHao { public static void main(String[] args) { Scanner input=new Scanner(System.in); String s=input.next(); System.out.println(solution(s)); } public static boolean solution(String s){ myCharStack stack1=new myCharStack(); char currentCorrectChar; for(int i=0;i<s.length();i++) { switch (s.charAt(i)) { case '(': stack1.push(')'); break; case '[': stack1.push(']'); break; case '{': stack1.push('}'); break; default: currentCorrectChar = stack1.pop(); if (currentCorrectChar != s.charAt(i)) return false; } } if(!stack1.isEmpty()) return false; return true; } }
2021年12月13日
87 阅读
0 评论
0 点赞
2021-11-28
java练习2
看不懂的链表public class NodeTest { public static void main(String[] args) { Node node1 = new Node(1, "李白1", "刺客1"); Node node2 = new Node(2, "李白2", "刺客2"); Node node3 = new Node(3, "李白3", "刺客3"); Node node4 = new Node(4, "李白4", "刺客4"); Node node5 = new Node(5, "李白5", "刺客5"); Node node6 = new Node(5, "李白", "刺客5"); SingleLinkedList singleLinkedList = new SingleLinkedList(); singleLinkedList.add(node1); singleLinkedList.add(node2); singleLinkedList.add(node4); singleLinkedList.add(node5); singleLinkedList.add2(node3); singleLinkedList.delete(3); singleLinkedList.delete(6); singleLinkedList.change(node6); singleLinkedList.change(1, "李白6", "刺客6"); singleLinkedList.show(); } } class SingleLinkedList{ private Node head=new Node(0, "", ""); public void add(Node node){ Node temp = head; while (true){ if (temp.next == null){ break; } temp = temp.next; } temp.next = node; } public void add2(Node node){ Node temp = head; boolean flag = false; while (true){ if (temp.next == null){ break; } if (temp.next.no > node.no){ break; }else if (temp.next.no == node.no){ flag = true; break; } temp = temp.next; } if (flag){ System.out.println("编号已经存在,不能添加"); }else { node.next = temp.next; temp.next = node; } } public void delete(int no){ Node temp = head; boolean flag = false; while (true){ if (temp.next == null){ break; } if (temp.next.no == no){ flag = true; break; } temp = temp.next; } if (flag){ temp.next = temp.next.next; }else { System.out.println("不存在"); } } public void change(int no, String name, String type){ if(head.next == null){ System.out.println("链表为空"); return; } Node temp = head.next; boolean flag = false; while (true){ if(temp == null){ System.out.println("没有找到数据"); break; } if (temp.no == no){ flag = true; break; } } if (flag){ temp.name = name; temp.type = type; } } public void change(Node node){ Node temp = head; //boolean flag = false; delete(node.no); add2(node); } public void show(){ if (head.next == null){ System.out.println("该链表为空"); return; } Node temp = head.next; while (true){ if (temp == null){ break; } System.out.println(temp); temp = temp.next; } } } class Node{ public int no; public String name; public String type; public Node next; public Node(int no, String name, String type){ this.no = no; this.name = name; this.type = type; } @Override public String toString() { return "Node{" + "no=" + no + ", name='" + name + '\'' + ", type='" + type + '\'' + '}'; } }
2021年11月28日
62 阅读
0 评论
0 点赞
2021-11-14
java练习1
一.例题1.打印三角形效果:代码:public class triangle { public static void main(String[] args){ //public private for (int i = 0; i < 5; i++){ for (int j = 0; j <= i; j++){ System.out.print("*"); } System.out.println(); } } }结果:* ** *** **** *****2.打印三角形pro效果:代码1:在第一个的基础上另外循环一次,补出来下面的部分public class trianglepro { public static void main(String[] args){ for (int i = 0; i < 5; i++){ for (int j = 0; j <= i; j++){ System.out.print("*"); } System.out.println(); } for (int i = 4; i > 0; i--){ for (int j = 0; j < i; j++){ System.out.print("*"); } System.out.println(); } } }代码2:使用绝对值(有点难)public class trianglepro { public static void main(String[] args){ for (int i = 0; i < 5*2-1; i++){ //Math.abs() 绝对值 for (int j = 0; j < 5 - Math.abs(4-i); j++){ System.out.print("*"); } System.out.println(); } } }结果:* ** *** **** ***** **** *** ** *3.打印三角形promax效果:代码:public class trianglepromax { public static void main(String[] args){ for (int i = 0; i < 5*2-1; i++) { for (int j = 0; j < Math.abs(4-i); j++) { System.out.print(" "); } for (int j = 0; j < (5-Math.abs(4-i))*2 - 1; j++) { System.out.print(i%2); } System.out.println(); } } }结果: 0 111 00000 1111111 000000000 1111111 00000 111 0 4.打印三角形promax远峰蓝(很离谱)效果代码:import java.awt.*; import javax.swing.JLabel ; import javax.swing.JFrame ; public class TriangleProMaxSierraBlue { public static void main(String args[]){ JFrame frame = new JFrame("TriangleProMaxSierraBlue") ; frame.setLayout(new FlowLayout()); String str=""; for(int i=0;i<5*2-1;i++){ for(int j=0;j<Math.abs(4-i);j++){ str+=" "; } for(int j=0;j<(5-Math.abs(4-i))*2-1;j++){ str+=i%2; } //这里补齐了后面的空格 for(int j=0;j<Math.abs(4-i);j++){ str+=" "; } JLabel lab = new JLabel(str,JLabel.CENTER) ; // 实例化标签对象 Font font = new Font("宋体", Font.PLAIN, 25); lab.setFont(font); lab.setForeground(new Color(173,198,220));; frame.add(lab) ; // 将组件件入到面板之中 str=""; } Dimension dim = new Dimension() ; dim.setSize(200,350) ; //窗体的大小 frame.setSize(dim) ; //设置窗体大小 Point point = new Point(500,100) ; // 设置坐标 frame.setLocation(point) ; //设置窗体坐标 frame.setVisible(true) ; //设置窗体可见 } }结果:就是上面的图片,不再重复5.打印三角形(输入版)代码:import java.util.Scanner; public class triangle_input { public static void main(String[] args){ //这里是输入 Scanner input = new Scanner(System.in); int num = input.nextInt(); for (int i = 0; i < num; i++){ for (int j = 0; j < i + 1; j++){ System.out.print("*"); } System.out.println(); } } } 结果:4 * ** *** ****2.面试题(看不懂,一脸懵逼)题目:/* 有一个方阵,方阵中有男生0和女生1。 一个女生上、下、左、右的女生与她本人同属于一朵"花"。 方阵中有多少"花"? */ public class flowerNumber { public static void main(String[] args){ int[][] studentCube={{0,0,1,1,1}, {1,0,1,0,0}, {1,1,1,0,1}, {0,0,0,0,0}, {1,1,0,1,1}}; System.out.print("Number of flowers is "+solution(studentCube)); } public static int solution(int[][] studentCube){ int flowerNum=0; //输入内容 return flowerNum; } }代码:(用到了迭代,看不懂啊)这个是彬酱的有关迭代的递归和迭代public class flowerNumber { public static void main(String[] args){ int[][] studentCube={{0,0,1,1,1}, {1,0,1,0,0}, {1,1,1,0,1}, {0,0,0,0,0}, {1,1,0,1,1}}; System.out.print("Number of flowers is "+solution(studentCube)); } public static int solution(int[][] studentCube){ int flowerNum=0; for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ if(studentCube[i][j]==0) continue; flowerNum++; tagFemaleToMale(studentCube,i,j); } } return flowerNum; } public static void tagFemaleToMale(int[][] studentCube,int i,int j){ studentCube[i][j]=0; if(i<4){ if(studentCube[i+1][j]==1) tagFemaleToMale(studentCube,i+1,j); } if(j<4){ if(studentCube[i][j+1]==1) tagFemaleToMale(studentCube,i,j+1); } if(i>0){ if(studentCube[i-1][j]==1) tagFemaleToMale(studentCube,i-1,j); } if(j>0){ if(studentCube[i][j-1]==1) tagFemaleToMale(studentCube,i,j-1); } } }结果:Number of flowers is 4三.总结要加快进度看视频啊,要来不及了很多绝对值那里需要再看看递归和迭代搞不懂,有机会就学
2021年11月14日
68 阅读
0 评论
0 点赞