ex1parta.java

来自「Snunuiot are flying as far as you send t」· Java 代码 · 共 48 行

JAVA
48
字号
import java.util.Scanner;

public class Ex1PartA {
	
	public static void main (String[] args){
		
		Scanner sc = new Scanner(System.in);
		
//		variable declarations:
		int sum,limit, target,a,b,c;
		double fraction;
		
//		reading the values of 'limit' and 'target' from the user:
		System.out.print("Enter the limit: ");
		limit = sc.nextInt();
		System.out.print("Enter the target: ");
		target = sc.nextInt();
		while (target==0){
			System.out.print("Invalid input.\nEnter the target: ");
			target = sc.nextInt();
		}
//		computing and printing the summation of the two numbers:
		sum = limit + target;
		System.out.println("The value of the operation " 
				+ limit+"+" + target + " is " + sum);
		
//		computing and printing the division of 'limit' with 'target':
		fraction = (double)limit / (double)target;
		System.out.println("The value of the operation " + limit + "/"
				+ target + " is " + fraction);

		System.out.println ("----------");

		for (a=0;a<=limit ;a=a+1){
			for (b=0;b<=limit ;b=b+1){
				for (c=0;c<=limit ;c=c+1){
					if ((a+b+c)==target) {
						System.out.println ("a = "+a+",b = "+b+",c = "+c);
					}
				}
			}
		}
		System.out.println ("----------");

	}
	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?