两道简单的面试题 java


public class test122345 {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  test122345 tt= new test122345();
  String[] number = {"1","2","2","3","4","5"};
  String numberstr="122345";
  int b=0;
  int count=0;
  for(int i=122345;i<=543221;i++)
  {
   if(tt.re('1', String.valueOf(i), 1)==-1 || tt.re('2', String.valueOf(i), 2)==-1 || tt.re('3', String.valueOf(i), 1)==-1 || tt.re('4', String.valueOf(i), 1)==-1 || tt.re('5', String.valueOf(i), 1)==-1)
   {   
   
   }
   else
   {
    if(tt.re2("4", String.valueOf(i), 3)==-1)
    {
     
    }
    else
    {
    for(int j=0;j<number.length;j++)
    {
     String geti = String.valueOf(i);    
     String getstr = geti.substring(j,j+1); 
     b = numberstr.indexOf(getstr);
     
     int w1 = 0;
     w1 = geti.indexOf("1");
     if(w1<=4)
     {
     char c5 = geti.charAt(w1+1);   
     if(c5=='5')
     {
      b = -1;
     }     
     }
     
     int w5 = 0;
     w5 = geti.indexOf("5");
     if(w5<=4)
     {
     char c11 = geti.charAt(w5+1);   
     if(c11=='1')
     {
      b = -1;
     }    
     }
     
     if(b == -1)
     {
      break;
     }
    }
    if(b != -1)
    { 
     count = count+1;
     System.out.println("i:"+i);
    } 
    }
   }
  }
  System.out.println("count:"+count);
 }
 public int re(char c,String geti,int sum)
 {
  int count = 0;
  char getChar;
  for(int i=0;i<geti.length();i++)
  {
   getChar = geti.charAt(i);
   if(c == getChar)
   {
    count = count + 1;
   }
  }
  if(count>sum)
  {
   return -1;
  }
  else
  {
   return 0;
  }  
 }
 public int re2(String s,String geti,int wei)
 {
  int w4 =0;
  w4 = geti.indexOf(s);     
  if (w4==wei)
  {
   return -1;
  }  
  else
  {
   return 0;
  }  
 }
}
i:122345
i:122354
i:122534
i:122543
i:123245
i:123254
i:123524
i:123542
i:124235
i:124253
i:124325
i:124352
i:124523
i:124532
i:125234
i:125243
i:125324
i:125342
i:132245
i:132254
i:132524
i:132542
i:134225
i:134252
i:134522
i:135224
i:135242
i:142235
i:142253
i:142325
i:142352
i:142523
i:142532
i:143225
i:143252
i:143522
i:145223
i:145232
i:145322
i:212345
i:212354
i:212534
i:212543
i:213245
i:213254
i:213524
i:213542
i:214235
i:214253
i:214325
i:214352
i:214523
i:214532
i:221345
i:221354
i:223145
i:223541
i:224135
i:224531
i:225314
i:225341
i:231245
i:231254
i:232145
i:232541
i:234125
i:234521
i:235214
i:235241
i:241235
i:241253
i:241325
i:241352
i:242135
i:242531
i:243125
i:243521
i:245213
i:245231
i:245312
i:245321
i:252134
i:252143
i:252314
i:252341
i:253124
i:253142
i:253214
i:253241
i:254123
i:254132
i:254213
i:254231
i:254312
i:254321
i:312245
i:312254
i:312524
i:312542
i:314225
i:314252
i:314522
i:321245
i:321254
i:322145
i:322541
i:324125
i:324521
i:325214
i:325241
i:341225
i:341252
i:342125
i:342521
i:345212
i:345221
i:352124
i:352142
i:352214
i:352241
i:354122
i:354212
i:354221
i:412235
i:412253
i:412325
i:412352
i:412523
i:412532
i:413225
i:413252
i:413522
i:421235
i:421253
i:421325
i:421352
i:422135
i:422531
i:423125
i:423521
i:425213
i:425231
i:425312
i:425321
i:431225
i:431252
i:432125
i:432521
i:435212
i:435221
i:452123
i:452132
i:452213
i:452231
i:452312
i:452321
i:453122
i:453212
i:453221
i:521234
i:521243
i:521324
i:521342
i:522134
i:522143
i:522314
i:522341
i:523124
i:523142
i:523214
i:523241
i:524123
i:524132
i:524213
i:524231
i:524312
i:524321
i:531224
i:531242
i:532124
i:532142
i:532214
i:532241
i:534122
i:534212
i:534221
i:541223
i:541232
i:541322
i:542123
i:542132
i:542213
i:542231
i:542312
i:542321
i:543122
i:543212
i:543221
count:198

public class Sum
{
 public static void main(String [] argv)
{
 int a=11;
 int b=4;
 System.out.println("b:" + b);
 System.out.println("a:" + a);
 a=a+b;//15
 b=a-b;//11
 a=a-b;//15-11
 System.out.println("b:" + b);
 System.out.println("a:" + a);
a = a^b;
System.out.println(a);
b=a^b;
a=a^b;
System.out.println(a);
System.out.println(b);
}
}

 

public class Sum2
{
 public static void main(String args[])
 {
   int a,b;
   a=10;
   b=8;
   System.out.println("交?之前的a与b是:"+a+","+b);
   b=a+(a=b)*0; //a与b的交?
   System.out.println("交?之后的a与b是:"+a+","+b);
 }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值