对于两种变量的交换,我发现四种方法,下面我用Java来演示一下. 1.利用第三个变量交换数值,简单的方法. (代码演示一下) class TestEV //创建一个类 { public static void main(String[]args) { int x =5,y=10; //定义两个变量 int temp = x; //定义第三临时变量temp并提取x值 x = y; //把y的值赋给x y = temp; //然后把临时变量temp值赋给y System.out.println("x
题出自https://leetcode.com/problems/rotate-image/ 内容为: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up: Could you do this in-place? 简单的说就是给出一个n*n的二维数组,然后把这个数组进行90度顺时针旋转,而且不能使用额外的存储空间. 最初拿到这道题
练习1:写一个程序,打印从1到100的值 public class Print1To100{ public static void main(String args[]){ for(int i = 1 ; i <= 100 ; i++){ System.out.println("value:" + i) ; } } } 练习2:写一个程序,产生25个int类型的随机数.对于每个随机值,使用if-else语句来将其分类为大于.小于或等于紧随它而随机生成的值. public clas