欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

.java,

来源: javaer 分享于  点击 4183 次 点评:53

.java,


Class Program

  static void Main()  
   {    
      bool isOpt = true   
      while(isOpt)    
      {      
         string str = Console.ReadLine();        
         if(Math.IsInteger(str))      
          {          
           string[] data = str.Split(' ');  
          int a = Convert.ToInt32(data[0]);                    
    int b = Convert.ToInt32(data[1]);                    
  Console.WriteLine(Math.Sum(a,b));                 
  Console.WriteLine("是否继续计算(Y/N):");            
  isOpt = (Console.ReadLine().Trim().ToUpper() == "Y");      
        }       
       else       
          {           
           Cosnole.WriteLine("输入格式不正确,请重新输入:"); 
           }     
        }  
   }
  }
    Class Math
  {  
  public static bool IsInteger(string str) 
 {     
  bool isInteger = true;   
  int i = 0;    
  while(isInteger)  
   {        
       isInteger = (Char.ConvertToUtf32(str,i) >= 48 && Char.ConvertToUtf32(str,i) <= 57 || Char.ConvertToUtf32(str,i) == 32);
        i++;     
    }   
  return isInteger;
  } 
 public static int Sum(int a, int b) 
{     
return a + b; 
 }
}

相关文章

    暂无相关文章
相关栏目:

用户点评