学JAVA (MARS)中2014年3月31日17:35:08

来源:互联网 发布:unity3d 脚本 粒子 编辑:程序博客网 时间:2024/05/29 17:16

(1)为啥String类型的不行呢,而换成int的就可以了?

附代码:import java.util.Scanner;

public class Hello{

public static void main(String[] args){

Scanner input = new Scanner(System.in);

System.out.println("play1 is ");

String play1 = input.next(); 

System.out.println("play2 is");

String play2 =input.next() ;

if( (play1 == "石头"&&play2 =="石头")||(play1 == "剪子"&&play2 == "剪子")||(play1 == ""&&play2 == "") ){

System.out.println("");

}

else if( (play1 == "石头"&&play2 == "剪子")||(play1 == "剪子"&&play2 =="")||(play1 == ""&&play2 =="石头") ){

System.out.println("play1");

}

else {

   System.out.println("play2");

}

}

}

 

 

 

2)全局变量与局部变量的作用(boolean b = false 的位置),和int k = i%j;

if(k==0){

 b =true;

 }

}

if(!b)  的  判断关系(迷糊不清)

 

 

public class Hello{

public static void main(String[] args){

boolean b = false;

for(int i = 100;i<201;i++){

//boolean b = false;

for(int j = 2;j<i;j++){

int k = i%j;

if( k==0){

 b =true//就是说,只要有一个(例如:121 取余11为0,则b为true,往下走,非b意思说一个都没有使b为true,则输出i)使K==0的话,b就为true,....

 }

}

if(!b){

System.out.println(i);

}

}

System.out.println("zz");} }

 

//注意:当本类当中,一个构造函数(使用this)调用本类中其他的构造函数时,this这条代码一定要放在代码的第一条语句

1)类的定义方法  class  Dog{

属性;也叫成员变量

方法;也叫成员函数

}

(2)生成对象的方法

格式:类名 对象名 = new 类名();

例如:Dog  dog = new Dog();

    <1>创建一个Dog的引用;

<2>创建一个Dog的对象;

<3>将创建的Dog的对象赋给这个引用。

(3)对象和对象的引用

(4)函数的重载

两个函数或者多个参数在同一类中;函数名相同,参数列表不同

(5)构造函数

 类名(){

无返回值类型的定义;名字必须和类名相同。作用;当使用new的时候,会形成这个类的对象;

}


0 0