zoukankan      html  css  js  c++  java
  • 软件工程个人作业01

    1.程序设计思想:

    利用随机数产生两个数和运算符,加入定制数量,利用for循环实现输出,在每个+-*/里进行判断,不能出现假分数,不能出现负数,在加入结果计算,并且进行判断。

    2.源程序代码:

    package yunsuan;
    import java.util.Scanner;
    public class yunsuan {
    	public static void main(String[]args)
    	{
    		   
    		Scanner in=new Scanner(System.in);
    		System.out.println("请输入要打印的数量");
    		int m=in.nextInt();
    		int answer=0;
    		for(int n=0;n<m;n++)
    		{
    			 int a,b;
    			   char[] c1={'+','-','*','/'};
    		       a = (int) ( Math.random() * 100 );
    		       b = (int) ( Math.random() * 100 );
    		      int  c=(int)(Math.random()*4);
    	      if(c1[c]=='+')
    	      {
    	    	  System.out.print(a);
    		       System.out.print('+');
    		       System.out.print(b);
    		       System.out.print("=");
    		       System.out.println();
    		       System.out.println("请输入答案:");
    		       Scanner in1=new Scanner(System.in);
    			      int q=in1.nextInt();
    		       answer=a+b;
    		    	  if(q==answer)
    		    	  {
    		    		  System.out.println("回答正确!");
    		    	  }
    		    	  else 
    		    		  System.out.println("回答错误!");
    		       
    	      }
    	      else if(c1[c]=='-')
    	      {
    	    	  if(a>b)
    	    	  {
    	    		  System.out.print(a);
    		       System.out.print('-');
    		       System.out.print(b);
    		       System.out.print("=");
    		       System.out.println();
    		       System.out.println("请输入答案:");
    		       Scanner in1=new Scanner(System.in);
    			      int q=in1.nextInt();
    		 	  answer=a-b;
        		  if(q==answer)
        		  {
    	    		  System.out.println("回答正确!");
    	    	  }
    	    	  else 
    	    		  System.out.println("回答错误!");
    	    	  }
    		       else
    		    	   m++;
    	      }
    	      else if(c1[c]=='*')
    	      {
    	       System.out.print(a);
    	       System.out.print('*');
    	       System.out.print(b);
    	       System.out.print("=");
    	       System.out.println();
    	       System.out.println("请输入答案:");
    	       Scanner in1=new Scanner(System.in);
    		      int q=in1.nextInt();
    	       answer =a*b;
     		  if(q==answer)
     		  {
    	    		  System.out.println("回答正确!");
    	    	  }
    	    	  else 
    	    		  System.out.println("回答错误!");
    	       
    	      }
    	      else if(c1[c]=='/')
    	      {
    	    	  if(a<b)
    	    	  {
    	    		  System.out.print(a);
    		       System.out.print('/');
    		       System.out.print(b);
    		       System.out.print("=");
    		       System.out.println();
    		       System.out.println("请输入答案:");
    		       Scanner in1=new Scanner(System.in);
    			      int q=in1.nextInt();
    		       answer=a/b;
    	    		  if(q==answer)
    	    		  {
    		    		  System.out.println("回答正确!");
    		    	  }
    		    	  else 
    		    		  System.out.println("回答错误!");
    	    	  }
    		       else
    		    	   m++;
    	      }
    		}
          }
    	}
    	
    

      3.运行结果截图:

    4.课上未完成原因:

    因为Eclipse运行java代码出现某些故障,所以导致未能按时完成课堂作业

  • 相关阅读:
    hdu 2490 队列优化dp
    poj 1836 LIS变形
    hdu 3410 单调栈
    51nod 1437
    51nod 1215 单调栈/迭代
    51nod 1102 单调栈
    51nod 1272 思维/线段树
    51nod 1279 单调栈
    SpringMVC收藏
    今天接触枚举类型,感觉是C里面应该才有的东西
  • 原文地址:https://www.cnblogs.com/1998lu/p/6506044.html
Copyright © 2011-2022 走看看