黑马程序员_小练习

----------------------------------------------------------------------------- android培训java培训、期待与您交流! --------------------------------------------------------------------------------

注:按Java规范书写程序代码,如果你认为程序有错误,请指出,并说明程序错误原因。

1.
class Demo
{
 void show(int a,int b,float c){}
}


A.void show(int a,float c,int b){}//yes

B,void show(int a,int b,float c){}//一模一样。不可以出现在同一个类中。

C.int show(int a,float c,int b){return a;}//yes。

D.int show(int a,float c){return a;}//yes

哪个答案和show函数重载。


--------------------------------------------------
2.写出结果。
class Demo
{
 public static void main(String[] args)
 {
  int x=0,y=1;
  if(++x==y--&x++==1||--y==0)
   System.out.println("x="+x+",y="+y);
  else
   System.out.println("y="+y+",x="+x);
 }
}

 

--------------------------------------------------
3.
写出输出结果。
class Demo
{
 public static void main(String[] args)
 {
  int a=3,b=8;

  int c=(a>b)?a++:b++;
  System.out.println("a="+a+"\tb="+b+"\tc="+c);  //3 9 8

  int d=(a>b)?++a:++b;
  System.out.println("a="+a+"\tb="+b+"\td="+d);  //3 10 10

  int e=(a<b)?a++:b++;
  System.out.println("a="+a+"\tb="+b+"\te="+e);  //4 10 3

  int f=(a<b)?++a:++b;
  System.out.println("a="+a+"\tb="+b+"\tf="+f);  //5 10 5
 }
}

--------------------------------------------------
4.写出结果。
class Demo
{
 public static void main(String[] args)
 {
  int m=0,n=3;
  if(m>0)

   if(n>2)
    System.out.println("A"); 
  else
   System.out.println("B");
 }
}
没有结果。
--------------------------------------------------
5.写出结果。
public class Demo
{
 public static void main(String []args)
 {
  int i = 0, j = 5;
  tp: for (;;)
  {
   i++;
   for(;;)
   {
    if(i > j--)
     break tp;
   }
  }
  System.out.println("i = " + i + ", j = "+ j); i=1,j=-1;
 }
}   

 

--------------------------------------------------
6.写出结果。
class Demo     
{
 public static void main(String[] args)
 {
  String foo="blue";
  boolean[] bar=new boolean[2];
  if(bar[0])//boolean类型的数组默认初始化值是false。
  {
         foo="green";
     }
  System.out.println(foo);
 }
}  

 

--------------------------------------------------
7.写出结果。
public class Test     
{
 public static void leftshift(int i, int j)
 {
     i+=j;
 }
 public static void main(String args[])
 {
  int i = 4, j = 2;
  leftshift(i, j);
  System.out.println(i); //4  和leftShift函数没关系。
 }
}


--------------------------------------------------
8.写出结果。
public class Demo
{
 public static void main(String[] args)
 {
  int[] a=new int[1];
  modify(a);
  System.out.println(a[0]); //1
 }
 public static void modify(int[] a)
 {
  a[0]++;
 }
}


--------------------------------------------------
9.
class Test
{
 public static void main(String[] args)
 {
  String foo=args[1];
  String bar=args[2];
  String baz=args[3];
 }
}
d:\>java Test Red Green Blue

what is the value of baz?
  A. baz has value of ""
  B. baz has value of null
  C. baz has value of "Red"
  D. baz has value of "Blue"
  E. baz has value of "Green"
  F. the code does not compile
  G. the program throw an exception

--------------------------------------------------

11.
简述:函数在程序中的作用以及运行特点。。

 


--------------------------------------------------
12.
打印99乘法表


--------------------------------------------------
13.打印下列图形
    *
   * *
  * * *
 * * * *
* * * * *
 

------------------------------------------------------
14.
下面哪个数组定义是错误的。
并对错误的答案加上单行注释,写出错误的原因。
A,float[]=new float[3]; //没有数组引用名称。
B, float f2[]=new float[];//数组没有长度。
C, float[] f1=new float[3];//yes。
D, boolean[] b={"true","false","true"};// 错误,数据类型不匹配。"true"这是字符串类型。
E, double f4[]={1,3,5}; //yes  double d = 1; s.o.p(d);//1.0;
F, int f5[]=new int[3]{2,3,4};  //错,右边中括号不能写具体数值,因为数据的元素和个数都在大括号体现了。
G, float f4[]={1.2,3.0,5.4};//错误。因为数组中的元素值都是double,加上f就对了。

 

----------------------------------------------------------------------------- android培训java培训、期待与您交流!--------------------------------------------------------------------------------
详细请查看:http://edu.csdn.net/heima/

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
黑马程序员多线程练习题主要包括两个问题。第一个问题是如何控制四个线程在打印log之前能够同时开始等待1秒钟。一种解决思路是在线程的run方法中调用parseLog方法,并使用Thread.sleep方法让线程等待1秒钟。另一种解决思路是使用线程池,将线程数量固定为4个,并将每个调用parseLog方法的语句封装为一个Runnable对象,然后提交到线程池中。这样可以实现一秒钟打印4行日志,4秒钟打印16条日志的需求。 第二个问题是如何修改代码,使得几个线程调用TestDo.doSome(key, value)方法时,如果传递进去的key相等(equals比较为true),则这几个线程应互斥排队输出结果。一种解决方法是使用synchronized关键字来实现线程的互斥排队输出。通过给TestDo.doSome方法添加synchronized关键字,可以确保同一时间只有一个线程能够执行该方法,从而实现线程的互斥输出。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [黑马程序员——多线程10:多线程相关练习](https://blog.csdn.net/axr1985lazy/article/details/48186039)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值