几个java小题,用控制台实现即可(着急在线等)

FULIQIANG1 2013-04-11 10:50:20
1.从键盘输入两个整数,两个数之间用空格隔开,以回车键结束:
123 345
123+345 = 468
2.从键盘输入两个整数,两个数之间用空格隔开,以回车键结束:
12 34
请从键盘上输入运算符号,以回车键结束。
*
12* 34 = 408
3.要求:输入某个工资数,计算并输出应缴纳税额

4.编写程序求解一元二次方程。

本人是做.net的,没java环境,需要能实现的编译后的程序,哪位高手改实现了,立刻结贴给分。跪谢
...全文
221 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
Cute_Tiger 2013-04-11
  • 打赏
  • 举报
回复
引用 6 楼 xsd219222 的回复:
简单的都被人做完了,来晚了,还好还有第三题。 Java code?1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253public class GeShui { public static void main(String……
第三题加了一些简单的验证,如下:

public class GeShui {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		// 非负浮点数判断
		String regex = "^\\d+(\\.\\d+)?$";
		int a = 0;
		String str = sc.next();

		Pattern pat = Pattern.compile(regex);
		Matcher mat = pat.matcher(str);
		boolean rs = mat.find();

		if(!rs){
			System.out.println("请输入合法数值。");
		}else{
			Double i = Double.parseDouble(str);
			if(i-3500<=0){
				a = 0;
			}else if (i - 3500 <= 1500) {
				a = 1;
			} else if (i - 3500 <= 4500) {
				a = 2;
			} else if (i - 3500 <= 9000) {
				a = 3;
			} else if (i - 3500 <= 35000) {
				a = 4;
			} else if (i - 3500 <= 55000) {
				a = 5;
			} else if (i - 3500 <= 80000) {
				a = 6;
			} else {
				a = 7;
			}

			switch (a) {

			case 1:
				System.out.println((i - 3500) * 0.03);
				break;
			case 2:
				System.out.println((i - 3500) * 0.10 - 105);
				break;
			case 3:
				System.out.println((i - 3500) * 0.20 - 555);
				break;
			case 4:
				System.out.println((i - 3500) * 0.25 - 1005);
				break;
			case 5:
				System.out.println((i - 3500) * 0.30 - 2755);
				break;
			case 6:
				System.out.println((i - 3500) * 0.35 - 5505);
				break;
			case 7:
				System.out.println((i - 3500) * 0.45 - 13505);
				break;
			default:
				System.out.println("0");
			}
		}

	}
}
wypeng2010 2013-04-11
  • 打赏
  • 举报
回复
跟我的思路是一样的。
attach_finance 2013-04-11
  • 打赏
  • 举报
回复
这些程序都是能执行的,不过楼主是想说编译后的.class文件? 但是,貌似偶不会直接在回答这传文件。
attach_finance 2013-04-11
  • 打赏
  • 举报
回复
package test;

import java.util.Scanner;

public class Scan {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入二次的系数");
		int a = sc.nextInt();
		System.out.println("请输入一次的系数");
		int b = sc.nextInt();
		System.out.println("请输入常数");
		int c = sc.nextInt();
		System.out.println("请输入右边等号的常数");
		int d = sc.nextInt();
		double x = 0;
		if(a*x*x+b*x+c==d){
			System.out.println(x);
		}
	}
}
第四题。
attach_finance 2013-04-11
  • 打赏
  • 举报
回复
package test;

import java.util.Scanner;

public class Scan {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("输入工资:");
		String str = sc.nextLine();
		int money = Integer.parseInt(str);
		int b = money - 3500;
		int account = 0;
		if (b > 0 && b < 1500) {
			account += b * 0.03;
		} else if (b > 0 && b < 4500) {
			account += 1500 * 0.03 + (b - 1500) * 0.1;
		} else if (b > 0 && b < 9000) {
			account += 1500 * 0.03 + 3000 * 0.1 + (b - 4500) * 0.2;
		} else if (b > 0 && b < 35000) {
			account += 1500 * 0.03 + 3000 * 0.1 + 4500 * 0.2 + (b - 9000)
					* 0.25;
		} else if (b > 0 && b < 55000) {
			account += 1500 * 0.03 + 3000 * 0.1 + 4500 * 0.2 + 26000 * 0.25
					+ (b - 35000) * 0.3;
		} else if (b > 0 && b < 80000) {
			account += 1500 * 0.03 + 3000 * 0.1 + 4500 * 0.2 + 4500 * 0.25 + 26000*0.25
					+ 20000*0.3 +(b - 80000) * 0.35;
		} else if (b > 0 && b >= 80000) {
			account += 1500 * 0.03 + 3000 * 0.1 + 4500 * 0.2 + 4500 * 0.25
					+ (b - 35000) * 0.3;
		}
        System.out.println(account);
	}
}
不懂什么速算扣除数,楼主自己适当加一下,第三题
Cute_Tiger 2013-04-11
  • 打赏
  • 举报
回复
简单的都被人做完了,来晚了,还好还有第三题。

public class GeShui {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int a = 0;
		int i = sc.nextInt();
		if(i-3500<=0){
			a = 0;
		}else if (i - 3500 <= 1500) {
			a = 1;
		} else if (i - 3500 <= 4500) {
			a = 2;
		} else if (i - 3500 <= 9000) {
			a = 3;
		} else if (i - 3500 <= 35000) {
			a = 4;
		} else if (i - 3500 <= 55000) {
			a = 5;
		} else if (i - 3500 <= 80000) {
			a = 6;
		} else {
			a = 7;
		}
		switch (a) {

		case 1:
			System.out.println((i - 3500) * 0.03);
			break;
		case 2:
			System.out.println((i - 3500) * 0.10 - 105);
			break;
		case 3:
			System.out.println((i - 3500) * 0.20 - 555);
			break;
		case 4:
			System.out.println((i - 3500) * 0.25 - 1005);
			break;
		case 5:
			System.out.println((i - 3500) * 0.30 - 2755);
			break;
		case 6:
			System.out.println((i - 3500) * 0.35 - 5505);
			break;
		case 7:
			System.out.println((i - 3500) * 0.45 - 13505);
			break;
		default:
			System.out.println("0");
		}

	}
}
attach_finance 2013-04-11
  • 打赏
  • 举报
回复
package test;

import java.util.Scanner;

public class Scan {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		System.out.println("输入数字:");
		String str = sc.nextLine();
		System.out.println("输入运算符:");
		String[] obj = str.split(" ");
		String arr = sc.nextLine();
		int account = 0;
		if("*".equals(arr)){
			account = Integer.parseInt(obj[0])*Integer.parseInt(obj[1]);
		}else if("/".equals(arr)){
			account = Integer.parseInt(obj[0])/Integer.parseInt(obj[1]);
		}else if("+".equals(arr)){
			account = Integer.parseInt(obj[0])+Integer.parseInt(obj[1]);
		}else if("-".equals(arr)){
			account = Integer.parseInt(obj[0])-Integer.parseInt(obj[1]);
		}
		System.out.println(account);
	}
}
第二题。
attach_finance 2013-04-11
  • 打赏
  • 举报
回复
package test;

import java.util.Scanner;

public class Scan {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		String[] arr = str.split(" ");
		int account = 0;
		for(int i=0;i<arr.length;i++){
			account += Integer.parseInt(arr[i]);
		}
		System.out.println(account);
	}
}
第一题。
xxxxJustDoIt 2013-04-11
  • 打赏
  • 举报
回复
4 Scanner sc = new Scanner(System.in); // 求解x*x = i; int i = sc.nextInt(); double x = Math.sqrt(i); System.out.println(x); }
xxxxJustDoIt 2013-04-11
  • 打赏
  • 举报
回复
1

public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        System.out.println(sc.nextInt() + sc.nextInt());
        //System.out.println(sc.nextInt() * sc.nextInt());

    }
2

public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // System.out.println(sc.nextInt() + sc.nextInt());
        System.out.println(sc.nextInt() * sc.nextInt());

    }
十年彩虹 2013-04-11
  • 打赏
  • 举报
回复

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧