码迷,mamicode.com
首页 > 其他好文 > 详细

简单的四则运算

时间:2017-03-13 14:33:46      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:技术分享   oid   技术   text   over   bre   activity   err   ges   

这周的作业是四则运算,这个项目对于我来说可能有点困难,所以接下来的代码可能有些瑕疵。
java代码:

public class MainActivity extends siActivity {  
   private int a,b,c,ty;  
   private TextView tv;    
 private Button show,next;    
 @Override   
  protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);      
   setContentView(R.layout.activity_main);      
   tv=(TextView)findViewById(R.id.textView2);    
     show = (Button)findViewById(技术分享R.id.button3);    
     next = (Button)findViewById(技术分享R.id.button4);    
     sz();        
 switch (ty) {    
         case 0:                 tv.setText(a + "+" + b + "=" + "?");              
   break;       
         case 1:                 tv.setText(a + "-" + b + "=" + "?");              
   break;       
         case 2:                 tv.setText(a + "+" + b +"*"+ c + "=" + "?");         
   break;     
         case 3:                 tv.setText(a + "+" + b +"/"+ c + "=" + "?");             
    break;            
          case 4:                 tv.setText(a + "-" + b +"*"+ c + "=" + "?");                
    break;           
          case 5:                 tv.setText(a + "-" + b +"/"+ c + "=" + "?");               
   break;        
          case 6:                 tv.setText(a + "*" + b + "=" + "?");            
   break;         
           case 7:                 tv.setText(a + "/" + b + "=" + "?");            
     break;        
 }    
     show.setOnClickListener(new View.OnClickListener() {        
     @Override             public void onClick(View v) {      
           switch (ty) {                    
           case 0:                         tv.setText(a + "+" + b + "=" + (a + b));                     
     break;                  
            case 1:                         tv.setText(a + "-" + b + "=" + (a - b));               
      break;                 
            case 2:                         tv.setText(a + "+" + b +"*"+ c + "="+ (a+b*c));         
       break;          
           case 3:                         tv.setText(a + "+" + b +"/"+ c + "="+(a+b/c));          
       break;               
             case 4:                         tv.setText(a + "-" + b +"*"+ c + "="+(a-b*c));                  
       break;            
             case 5:                         tv.setText(a + "-" + b +"/"+ c + "="+(a-b/c));             
        break;                
               case 6:                         tv.setText(a + "*" + b + "=" + (a*b));                  
       break;             
               case 7:                         tv.setText(a + "/" + b + "=" + (a/b));                 
        break;            
     }            
 }        
 });     
    next.setOnClickListener(new View.OnClickListener() {           
  @Override             public void onClick(View v) {             
    sz();                 switch (ty) {                
            case 0:                         tv.setText(a + "+" + b + "=" + "?");                     
    break;       
           case 1:                         tv.setText(a + "-" + b + "=" + "?");                 
     break;               
             case 2:                         tv.setText(a + "+" + b +"*"+ c + "=" + "?");                 
      break;    
            case 3:                         tv.setText(a + "+" + b +"/"+ c + "=" + "?");         
       break;           
             case 4:                         tv.setText(a + "-" + b +"*"+ c + "=" + "?");           
      break;                  
              case 5:                         tv.setText(a + "-" + b +"/"+ c + "=" + "?");          
      break;               
               case 6:                         tv.setText(a + "*" + b + "=" + "?");                    
     break;                 
                case 7:                         tv.setText(a + "/" + b + "=" + "?");                     
    break;     
            }      
       }       
  });    
 }     private void sz(){    
     Random random = new Random();   
      random.nextInt();      
   a = random.nextInt(100);  
       b = random.nextInt(100);      
   c = random.nextInt(100);       
  ty = random.nextInt(8);   
  }
}
虚拟机运行
技术分享
技术分享
 

简单的四则运算

标签:技术分享   oid   技术   text   over   bre   activity   err   ges   

原文地址:http://www.cnblogs.com/chenbaiwan/p/6542248.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!