作业五 5.2 5.3

一.代码源

package aaa;

import java.text.DecimalFormat;

import java.util.Scanner;

public class Dada {

	

	public static void main(String[] args) {

		int condition=1 ;

		Dada dada = new Dada();

		Scanner scanner = new Scanner(System.in);

		while(condition==1){

		System.out.print("请输入第一个数:");

		double x = scanner.nextDouble();

		System.out.print("请输入第二个数:");

		double y = scanner.nextDouble();

		System.out.print("请输入运算符:");

		String s = scanner.next();

		char z = s.charAt(0);

		Test test=new Test();

		test.yunsuan(x, y, z);

		System.out.print("是否继续?1是  其他为否");

		condition = scanner.nextInt();}

		}

	}

	



package aaa;



import java.text.DecimalFormat;

public class Test{

public static int yunsuan(double x,double y,Character z){

		DecimalFormat r=new DecimalFormat(); 

		if(z.equals('+')){

			System.out.println(x+"+"+y+"=" + r.format((x+y)));

		} 

		return 1;

		}

public static int yunsuan1(double x,double y,Character z){

	DecimalFormat r=new DecimalFormat();

	if(z.equals('-')){

		System.out.println(x+"-"+y+"=" + r.format((x-y)));}

	return 1;}

public static int yunsuan2(double x,double y,Character z){

	DecimalFormat r=new DecimalFormat();

	 if(z.equals('*')){

			System.out.println(x+"*"+y+"=" + r.format((x*y)));

		}return 1;}

public static int yunsuan3(double x,double y,Character z){

	DecimalFormat r=new DecimalFormat();

	if(z.equals('/')){

		if(y==0){

			System.out.println("被除数不能为0");

		} else{

			System.out.println(x+"/"+y+"=" + r.format((x/y)));

		}

		

		

		}

	return 1;



	}

}

 二.测试结果

作业五 5.2 5.3

三.感想

     基础太差了,实力跟不上想法,虽然现在在努力的解决实力问题,可却不是短时间内可以改变的,所以老师的要求基本都没有怎么实现,但之后我一定会补交一份完整的作业!

 

你可能感兴趣的:(作业)