tthhr吧 关注:275贴子:4,223

java重新开始学

只看楼主收藏回复

public static void main(String[] args)
{
int showJava=1;
//showJava.toString()是错的,因为showJava是整型变量,不是类变量
Integer i=new Integer(showJava);
System.out.printf(i.toString());
}


IP属地:江苏来自Android客户端1楼2015-06-11 08:38回复
    public static void main(String[] args)
    {
    short a=1,b=2;
    String s=a>b?"a>b":"a<b";
    //条件式?成立返回值:失败返回值
    //等价于 if(a>b)s="a>b"else s="a<b"
    System.out.printf(s);
    }


    IP属地:江苏来自Android客户端2楼2015-06-11 08:44
    收起回复
      看到一个新的运算方式,以前跳过了,现在懂了
      中文名:异或
      外文名:exclusive OR
      数学符号:⊕
      英文简称:xor
      分享
      运算法则
      1. a ⊕ a = 0
      2. a ⊕ b = b ⊕ a
      3. a ⊕b ⊕ c = a ⊕ (b ⊕ c) = (a ⊕ b) ⊕ c;
      4. d = a ⊕ b ⊕ c 可以推出 a = d ⊕ b ⊕ c.
      5. a ⊕ b ⊕ a = b.
      6.若x是二进制数0101,y是二进制数1011
      则x⊕y=1110
      只有在两个比较的位不同时其结果是1,否则结果为0
      即“两个输入相同时为0,不同则为1”!


      IP属地:江苏来自Android客户端3楼2015-06-11 09:03
      回复
        public static void main(String[] args)
        {
        char ch='a';
        System.out.printf(""+(char)(ch^2)+(char)(ch^3));//异或操作完全不能用大脑算出
        ch='b';
        System.out.printf(""+(char)(ch^2)+(char)(ch^3));//ch='b'后以为结果没多大差别,结果。。
        }


        IP属地:江苏来自Android客户端4楼2015-06-11 09:18
        收起回复
          @绝望之阿奎拉


          IP属地:江苏来自Android客户端5楼2015-06-11 09:18
          回复
            九九乘法口诀,阶梯状
            public static void main(String[] args)
            {
            for (int i=1;i<10;i++)
            {
            for (int j=1;j<=i;j++)
            System.out.printf("%d*%d=%d ",j,i,i*j);
            System.out.println();
            }
            }


            IP属地:江苏来自Android客户端6楼2015-06-11 09:58
            收起回复
              一起来,今天电脑就会修好


              来自Android客户端7楼2015-06-11 10:37
              回复
                看了一个代码优化,
                boolean comp(int a,int b)
                {
                这是最原始的
                if (a==b)
                return ture;
                else
                return false;
                }
                然后各种优化
                1
                if (a==b)
                return true;
                return false;
                2
                return a==b?ture:false;
                3
                return a==b;
                真是够了@啊o额iu鱼 @DXKite


                IP属地:江苏来自Android客户端8楼2015-06-11 11:50
                收起回复
                  //我也来个优化,你用JAVA实现可好,
                  #include <stdio.h>
                  void swap1(int *a,int *b)
                  {
                  int t;
                  t=*a;
                  *a=*b;
                  *b=t;
                  }
                  int swap2(int *a,int *b)
                  {
                  if(a!=b)
                  {
                  *a=*a^*b;
                  *b=*a^*b;
                  *a=*a^*b;
                  }
                  }
                  int swap3(int *a,int *b)
                  {
                  /*未定义行为*/
                  (a!=b)&&(*a=*a^(*b=((*a=(*a^*b))^*b)));
                  }
                  int main()
                  {
                  int a=3,b=4;
                  swap1(&a,&b);
                  printf("%d,%d\n",a,b);
                  swap2(&a,&b);
                  printf("%d,%d\n",a,b);
                  swap3(&a,&b);
                  printf("%d,%d\n",a,b);
                  return 0;
                  }


                  IP属地:广东来自Android客户端9楼2015-06-11 12:20
                  收起回复
                    main和函数在栈内存里,凡是new出来的东西都在堆内存里


                    IP属地:江苏来自Android客户端10楼2015-06-11 12:23
                    回复


                      IP属地:江苏来自Android客户端11楼2015-06-11 12:23
                      回复
                        /*
                        交换int不行,然而,交换StringBuffer就有办法,
                        这就让我搞不清java的引用是干什么吃的了,
                        */
                        /*****************************************************
                        ^> File Name: swap.java
                        ^> Author: AoEiuV020
                        ^> Mail: 490674483@qq.com
                        ^> Created Time: 2015/06/11 - 12:52:44
                        ****************************************************/
                        public class swap
                        {
                        static void swap(StringBuffer a,StringBuffer b)
                        {
                        StringBuffer t=new StringBuffer();
                        t.delete(0,t.length());
                        t.append(a);
                        a.delete(0,a.length());
                        a.append(b);
                        b.delete(0,b.length());
                        b.append(t);
                        }
                        public static void main(String[] args)
                        {
                        StringBuffer a=new StringBuffer("aoeiuv");
                        StringBuffer b=new StringBuffer("AoEiuV");
                        swap(a,b);
                        System.out.println(a);
                        System.out.println(b);
                        }
                        }


                        IP属地:广东12楼2015-06-11 13:08
                        收起回复
                          import java.util.*;
                          import java.lang.*;
                          public class Main
                          {
                          static int a=3,b=4;
                          public static void main(String[] args)
                          {
                          swap1();
                          swap2();
                          swap3();
                          }
                          public static void swap1()
                          {
                          int t;
                          t=a;
                          a=b;
                          b=t;
                          System.out.println(a+" "+b);
                          }
                          public static void swap2()
                          {
                          int t;
                          t=a;
                          a=b;
                          b=t;
                          System.out.println(a+" "+b);
                          }
                          public static void swap3()
                          {
                          int t;
                          t=a;
                          a=b;
                          b=t;
                          System.out.println(a+" "+b);
                          }
                          }


                          IP属地:江苏来自Android客户端13楼2015-06-11 13:33
                          收起回复
                            class xxxx
                            {
                            private int a;
                            int b;
                            static int c;
                            a不能被外部用对象.a设置,也不能用类.a设置。
                            b不能用类里的static方法设置
                            c可以用类里的static方法设置
                            }


                            IP属地:江苏来自Android客户端14楼2015-06-12 11:10
                            收起回复
                              然后有什么区别呢?一个是私有的,一个是静态的。。感觉没关系


                              IP属地:江苏来自Android客户端15楼2015-06-12 11:33
                              回复