java吧 关注:1,256,084贴子:12,745,866
  • 13回复贴,共1

【间歇记录】开个帖子记录java学习

取消只看楼主收藏回复

我一定会坚持下去的
哪怕每年至少写一篇,我也会坚持奋斗下去的
fighting~~


1楼2014-05-05 17:39回复
    被三整除的数
    public class DivideTop53{
    public static void main(String args[]){
    int num = 0, i = 1;
    while (i <=100){
    if (i%3 == 0){
    num++;
    System.out.println(i + " ");
    }
    i++;
    if (num==5) break;
    }
    }
    }


    4楼2014-05-05 18:12
    回复
      斐波那契数列基础版
      public class Fibonacci41{
      public static void main(String args []){
      int num=1,a=0,b=0,c=1;
      while(num<6){
      num++;
      b=c;
      c=a+b;
      a=b;
      }
      System.out.println(c);
      System.out.println(num);
      }
      }
      忘了能不能行了。。。明天再尝试运行一下吧
      下一个升级版


      6楼2014-05-05 18:24
      回复
        斐波那契数列升级版
        可以手动输入想要的位数
        import java.util.Scanner;
        public class Fibonacci42{
        public static void main(String args []){
        Scanner in=new Scanner(System.in);
        System.out.println("请输入你想得到第几位的斐波那契数");
        int n=in.nextInt();
        int a=1,b=1;
        if (n<=0){
        System.out.println("你在开玩笑吧→.→");
        System.out.println("都知道斐波那契数列是从1开始的o.olll");
        }
        else if (n<3){
        System.out.println("你想要的是第" + n + "位的斐波那契数对吧\(^o^)/YES!");
        System.out.println("您要的结果是⇒" + "1");}
        else if (n>=3){
        int num=2,c=1;
        while(num<n){
        num++;
        b=c;
        c=a+b;
        a=b;
        }
        System.out.println("你想要的是第" + n + "位的斐波那契数对吧\(^o^)/YES!");
        System.out.println("您要的结果是⇒" + c);
        }
        }
        }


        7楼2014-05-05 18:26
        回复
          有1三个整数x=10,y=39,z=3,请把这三个数由小到大输出
          public class l2b{
          public static voidmain(String [] arg){
          int x=10,y=39, z=3;
          inta=(x<y)?x:y;
          intb=(a<z)?a:z;
          intc=(x>y)?x:y;
          int d=(c>z)?c:z;
          System.out.println(b+"<"+a+"<"+d);
          }
          }


          9楼2014-05-19 17:03
          回复
            学习成绩>=90分的同学用A表示,60-89分之间的用B表示,60分以下的用C表示。
            小明同学得的85分时输出结果。
            public class result{
            public static voidmain(String [] args){
            inti=85;
            if(i>60)
            {if(i>=90)
            System.out.println("A");
            elseSystem.out.println("B");
            }
            elseSystem.out.println("C");
            }
            }


            10楼2014-05-19 17:27
            回复
              打印出如下图案
              *
              **
              ***
              ****
              *****
              ******
              *******
              public class star1{
              public static void main(String [] args){
              for (int n=1;n<=5;n++){
              int hs=n;
              System.out.println();
              for (int i=1;i<=hs;i++)
              {
              System.out.print("*");
              }
              }
              }
              }


              11楼2014-05-19 17:29
              收起回复
                构造函数调用和普通调用
                public class Person{
                int id;
                int age;
                Person(int _id, int _age){
                id = _id;
                age = _age;
                }
                public static void main(String args []){
                Person tom = new Person(1,25);
                }
                }
                public class People{
                int id;
                int age=20;
                void People(int _id, int _age){
                id = _id;
                age = _age;
                }
                public static void main(String args []){
                People tom = new People();
                tom.People(1,25);
                }
                }


                14楼2014-05-23 17:16
                回复
                  插播一层
                  约定俗成命名规则
                  1.类名的首字母大写
                  eg HelloWorld Person
                  2.变量名和方法名的首字母小写
                  eg int i int j int furColor
                  main catchMouse
                  3.运用驼峰标识
                  eg furColor HelloWorld
                  →名字多个字母构成,首单词字母大写,后面每个单词首字母都大写,像驼峰


                  15楼2014-05-23 17:22
                  回复
                    内存调用分析例题
                    class BirthDate{
                    private int day;
                    private int month;
                    private int year;
                    public BirthDate(int d, int m, int y){
                    day = d;
                    month = m;
                    year = y;
                    }
                    public void setDay(int d ){
                    day = d;
                    }
                    public void setMonth(int m){
                    month = m;
                    }
                    public void setYear(int y){
                    year = y;
                    }
                    public int getDay(){
                    return month;
                    }
                    public int getMonth(){
                    return month;
                    }
                    public int getYear(){
                    return year;
                    }
                    public void display(){
                    System.out.println
                    (day + "-" + month + "-" + year);
                    }
                    }
                    public class Test{
                    public static void main (String args []){
                    Test test = new Test();
                    int date = 9;
                    BirthDate d1= new BirthDate(7,7,1970);
                    BirthDate d2= new BirthDate(1,1,2000);
                    test.change1(date);
                    test.change2(d1);
                    test.change3(d2);
                    System.out.println("date=" + date);
                    d1.display();
                    d2.display();
                    }
                    public void change1(int i){
                    i= 1234;
                    }
                    public void change2(BirthDate b){
                    b = new BirthDate(22,2,2004);
                    }
                    public void change3(BirthDate b){
                    b.setDay(22);
                    }
                    }


                    16楼2014-05-23 18:02
                    回复
                      public class TOF{
                      public static void main(String args[]){
                      int i = 1 , j = 2;
                      boolean flag1,flag2;
                      flag1 = (i>3)&&((i+j)>5);
                      System.out.println(flag1);
                      flag2 = (i<2)||((i+j)<6);
                      System.out.println(flag2);
                      }
                      }


                      17楼2014-05-28 14:32
                      回复
                        1+3+5+7+9+...+99 的写法
                        while语句
                        public class Add{
                        public static void main(String args []){
                        int i = 1;
                        int x = 0;
                        do {
                        x=x+i;
                        i+=2;
                        }
                        while (i<=99);
                        System.out.println(x);
                        }
                        }


                        18楼2014-05-30 13:00
                        回复
                          1+3+5+7+9+...+99 的写法
                          while语句
                          public class Add{
                          public static void main(String args []){
                          int i = 1;
                          int x = 0;
                          do {
                          x=x+i;
                          i+=2;
                          }
                          while (i<=99);
                          System.out.println(x);
                          }
                          }


                          19楼2014-05-30 13:00
                          回复
                            1+3+5+7+9+...+99 的写法
                            for语句
                            for语句1
                            public class AddFor1{
                            public static void main (String args []){
                            long f=0;
                            long result=0;
                            for (int i = 1 ; i <= 99 ; i+=2){
                            result=f+ i;
                            f=result;
                            }
                            System.out.println("result = " + result);
                            }
                            }
                            for语句 2
                            public class AddFor2{
                            public static void main (String args []){
                            long result=0;
                            for (int i = 1 ; i <= 99 ; i+=2){
                            result=result+ i;
                            }
                            System.out.println("result = " + result);
                            }
                            }


                            20楼2014-05-30 13:02
                            回复