Javase day02_作业

作业

package javaseday02;

import java.util.Scanner;

import org.junit.Test;

public class HomeWork {

输入一个数字,判断是一个奇数还是偶数。

@Test
	public void myTest01() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		System.out.println("输入数字:" + n);
		if (n % 2 == 1) {
			System.out.println("数字为奇数");
		} else {
			System.out.println("数字为偶数");
		}
	}

判断一个数字是否能被5和6同时整除(打印能被5和6整除),
或只能被5整除(打印能被5整除),或只能被6整除,
(打印能被6整除),不能被5或6整除,(打印不能被5或6整除

@Test
	public void myTest02() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		System.out.println("输入数字:" + n);
		if (n % 5 == 0) {
			if (n % 6 == 0) {
				System.out.println("数字能被5和6同时整除");
			} else {
				System.out.println("数字只能被5整除");
			}
		} else {
			if (n % 6 == 0) {
				System.out.println("数字只能被6整除");
			} else {
				System.out.println("数字不能被5或6整除");
			}
		}

	}

输入三个整数x,y,z,请把这三个数由小到大输出.

@Test
	public void myTest03() {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		System.out.println("输入数字 x:" + x);
		System.out.println("输入数字 y:" + y);
		System.out.println("输入数字 z:" + z);
		int s;
		if (x > y) {
			s = x;
			x = y;
			y = s;
		}
		if (x > z) {
			s = x;
			x = z;
			z = s;
		}
		if (y > z) {
			s = y;
			y = z;
			z = s;
		}
		System.out.println(x + " " + y + " " + z);
	}

输出0-9之间的数,但是不包括5。

@Test
	public void myTest04() {
		for (int i = 0; i < 10; i++) {
			if (i != 5)
				System.out.println(i);
		}
	}

编写一个程序,求整数n的阶乘,例如5的阶乘是12345。

@Test
	public void myTest05() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int sum = 1;
		for (int i = 1; i <= n; i++) {
			sum = sum * i;
			System.out.print(i);
			if (i != n)
				System.out.print("*");
		}
		System.out.println("=" + sum);
	}

由命令行输入一个4位整数,求将该数反转以后的数,如原数为1234,反转后的数位4321

@Test
	public void myTest06() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		System.out.println("输入4位整数:"+n);
	   int a1,a2,a3,a4;
	   a1=n/1000%10;
	   a2=n/100%10;
	   a3=n/10%10;
	   a4=n/1%10;
	   n=a4*1000+a3*100+a2*10+a1;
	   System.out.println("反转后的数为:"+n);
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值