本文共 6819 字,大约阅读时间需要 22 分钟。
import java.util.Scanner;public class book { public static void main(String[] args) { System.out.print("Enter two integers: "); Scanner input = new Scanner(System.in); int n1 = input.nextInt(); int n2 = input.nextInt(); int jb = Math.min(n1,n2); for(int i=jb;i>=1;i--) { if(n1%i==0&&n2%i==0) { System.out.println("The gcd is "+i); break; } } }}
public class book { public static void main(String[] args) { char ass = '!'; int count = 0; while(ass<='~') { System.out.print(ass+" "); count++; ass++; if(count%10==0) System.out.print("\n"); } }}
import java.util.Scanner;public class book { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter an integer: "); int ass = input.nextInt(); while(ass!=1) { for(int i=2;i<=ass;i++) { if(ass%i==0) { ass=ass/i; System.out.print(i+" "); break; } } } }}
import java.util.Scanner;public class book { public static void main(String[] args) { System.out.print("Enter the number of lines: "); Scanner input = new Scanner(System.in); int lines = input.nextInt(); for(int i=1;i<=lines;i++) { for(int j=1;j<=7-i;j++) System.out.print(" "); for(int j=i;j>1;j--) System.out.print(j+" "); for(int j=1;j<=i;j++) System.out.print(j+" "); System.out.print('\n'); } }}
public class book { public static void main(String[] args) { for(int i=1;i<=6;i++) { for(int j=1;j<=i;j++) System.out.print(j+" "); System.out.print('\n'); } for(int i=1;i<=6;i++) { for(int j=1;j<=7-i;j++) System.out.print(j+" "); System.out.print('\n'); } for(int i=1;i<=6;i++) { for(int j=1;j<=6-i;j++) System.out.print(" "); for(int j=i;j>=1;j--) System.out.print(j+" "); System.out.print('\n'); } for(int i=1;i<=6;i++) { for(int j=1;j<=i-1;j++) System.out.print(" "); for(int j=1;j<=7-i;j++) System.out.print(j+" "); System.out.print('\n'); } }}
public class book { public static void main(String[] args) { for(int i=0;i<8;i++) { for(int j=1;j<=7-i;j++) System.out.print(" "); for(int j=0;j =0;j--) System.out.printf("%5d",(int)(Math.pow(2,j))); System.out.print('\n'); } }}
public class book { public static void main(String[] args) { int lineBase = 0; int count = 0; for(int i = 2;i <= 1000;i++) { boolean isPrime = true; for(int j = 2;j
import java.util.Scanner;public class book { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Loan Amount: "); double amount = input.nextDouble(); System.out.print("Number of Years: "); int years = input.nextInt(); System.out.println("Interest Rate Monthly Payment Total Payment"); for(int i = 0;i<25;i++) { double rate = (0.125*i+5)/1200; double monthMoney = amount*rate/(1-1/Math.pow(1+rate,years*12)); System.out.printf("%-4.3f%% %-5.2f %-7.2f\n",0.125*i+5,monthMoney,monthMoney*12*years); } }}
import java.util.Scanner;public class book { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Loan Amount: "); double amount = input.nextDouble(); System.out.print("Number of Years: "); int years = input.nextInt(); System.out.print("Annual Interest Rate: "); double annualRate = input.nextDouble(); double monthRate = annualRate/1200; double monthPay = amount*monthRate/(1-1/(Math.pow(1+monthRate,12*years))); double total = monthPay*years*12; System.out.printf("Monthly Payment: %.2f\n",monthPay); System.out.printf("Total Payment: %.2f\n",total); System.out.println("Payment# Interest Principle Balance"); double balance = amount; for(int i=1;i<=years*12;i++) { double interest = monthRate*balance; double principle = monthPay-interest; balance = balance-principle; System.out.printf("%d\t\t %.2f\t\t%.2f\t\t%.2f\n",i,interest,principle,balance); } }}
public class book { public static void main(String[] args) { double l2r = 0; double r2l = 0; double base1 = 1.0; double base2 =50000.0; for(int i=1;i<=50000;i++) { l2r+=1/base1; base1+=1; } for(int i=1;i<=50000;i++) { r2l+=1/base2; base2-=1; } System.out.println("From left to right: "+l2r); System.out.println("From right to left: "+r2l); }}
public class book { public static void main(String[] args) { double sum = 0; for(int i =1;i<=97;i+=2) { sum+=1.0*i/(i+2); } System.out.println("The answer is "+sum); }}
public class book { public static void main(String[] args) { double item = 0.0; double sum = 0.0; for(int i=10000;i<=100000;i+=10000) { item = 1.0; sum = 0.0; for(int j=1;j<=i;j++) { sum+=1.0*item/(2*j-1); item*=(-1); } System.out.printf("i=%d, pi=%f\n",i,sum*4); } }}
public class book { public static void main(String[] args) { for(int i =10000;i<=100000;i+=10000) { double item = 1.0; double e = 1.0; for(int j=1;j<=i;j++) { item/=j; e+=item; } System.out.printf("i=%d, e=%f\n",i,e); } }}
转载地址:http://kuwai.baihongyu.com/