JAVA第二周 输入字符

2.6**

代码如下

package Digits;

import java.util.Scanner;

public class Digits {
	public static void main(String[] args) {
		System.out.println("Enter an integer between 0 and 1000 :");
		Scanner in = new Scanner(System.in);
		int a = 0, b = 0, c = 0;
		int num = in.nextInt();
		if (num < 1000 && num >= 0) {
			a = num % 10;
			b = (num % 100 - a) / 10;
			c = num / 100;
			System.out.println(a + b + c);
		} else {
			System.out.println("Sorry,the integer must be between 0 and 1000.");
		}
	}

}


运行结果

Enter an integer between 0 and 1000 :
932
14


2.24

代码如下

package Digits;

import java.util.Scanner;

public class RunwayLength {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		System.out.println("Enter v in meters/second(m/s) :");
		double v = in.nextDouble();
		System.out.println("Enter a in meters/second squared(m/s^2) :");
		double a = in.nextDouble();
		
		System.out.println("The minimum runway length for this airplane is "+0.5*v*v/a);
	}
}

运行结果

Enter v in meters/second(m/s) :
60
Enter a in meters/second squared(m/s^2) :
3.5
The minimum runway length for this airplane is 514.2857142857143





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值