课本第一章、第二章程序清单

第2周作业:教材第一章和第二章课本例题抄写
// 程序清单1-1
// System.out.println(“Welcome to Java!”);

// 程序清单1-2
// System.out.println(“Programming is fun”);
// System.out.println(“Fundamentals First”);
// System.out.println(“Problem Driven”);

// 程序清单1-3
// System.out.println((10.5+2*3)/(45-3.5));

// 程序清单1-4 语法错误
// System.out.println("Welcome to Java);

// 程序清单1-5运行错误
// System.out.println(1/0);

// 程序清单1-6逻辑错误
// System.out.println(“Celsius 35 is Fahrenheit degree”);
// System.out.println((9/5)*35+32);

// 程序清单2-1
// double radius;
// double area;
// radius=20;
// area=radiusradius3.14159;
// System.out.println("The area for the circle of radius “+radius+” is "+area);

// 程序清单2-2
// Scanner input=new Scanner(System.in);
// System.out.print(“Enter a number for radius:”);
// double radius=input.nextDouble();
// double area=radiusradius3.14159;
// System.out.println("The area for the circle of radius “+radius+” is "+area);

// 程序清单2-3
// Scanner input=new Scanner(System.in);
// System.out.print("Enter three numbers: ");
// double number1=input.nextDouble();
// double number2=input.nextDouble();
// double number3=input.nextDouble();
// double average=(number1+number2+number3)/3;
// System.out.println("The average of “+number1+” “+number2+” “+number3+” is "+average);

// 程序清单2-4
// final double PI=3.14159;
// Scanner input = new Scanner(System.in);
// System.out.print("Enter a number for radius: ");
// double radius=input.nextDouble();
// double area=radiusradiusPI;
// System.out.println("The area for the circle of radius “+radius+” is "+area);

// 程序清单2-5
// Scanner input=new Scanner(System.in);
// System.out.print(“Enter an integer for seconds: “);
// int seconds=input.nextInt();
// int minutes=seconds/60;
// int remainingSeconds=seconds%60;
// System.out.println(seconds+” seconds is “+minutes+” minutes and “+remainingSeconds+” seconds”);

// 程序清单2-6
// Scanner input=new Scanner(System.in);
// System.out.print(“Enter a degree in Fahrenheit:”);
// double fahrenheit=input.nextDouble();
// double celsius=(5.0/9)*(fahrenheit-32);
// System.out.println(“Fahrenheit “+fahrenheit+” is “+celsius+” in Celsius”);

// 程序清单2-7
// long totalMilliseconds=System.currentTimeMillis();
// long totalSeconds=totalMilliseconds/1000;
// long currentSecond=totalSeconds%60;
// long totalMinutes=totalSeconds/60;
// long currentMinute=totalMinutes%60;
// long totalHours=totalMinutes/60;
// long currentHour=totalHours%24;
// System.out.println(“Current time is “+currentHour+”:”+currentMinute+":"+currentSecond+" GMT");

// 程序清单2-8
// Scanner input=new Scanner(System.in);
// System.out.print("Enter purchase amount: ");
// double purchaseAmount=input.nextDouble();
// double tax=purchaseAmount0.06;
// System.out.println(“Sales tax is $”+(int)(tax
100)/100.0)

// 程序清单2-9
// Scanner input=new Scanner(System.in);
// System.out.print("Enter annual interest rate,e.g.,7.25%: ");
// double annualInterestRate=input.nextDouble();
// double monthlyInterestRate=annualInterestRate/1200;
// System.out.print("Enter number of years as an integer ,e.g.,5: ");
// int numberOfYears=input.nextInt();
// System.out.print("Enter loan amount ,e.g.,120000.95: ");
// double loanAmount=input.nextInt();
// double monthlyPayment=loanAmountmonthlyInterestRate/(1-1/Math.pow(1+monthlyInterestRate, numberOfYears12));
// double totalPayment=monthlyPaymentnumberOfYears12;
//
// System.out.println("The monthlyPayment is $: "+(int)(monthlyPayment100)/100.0);
// System.out.println("The totalPayment is $: "+(int)(totalPayment
100)/100.0);

	程序清单2-10
	Scanner input=new Scanner(System.in);
	System.out.print("Enter an amount in double,for example 11.56:");
	double amount=input.nextDouble();
	
	int remainingAmount=(int)(amount*100);
	
	int numberOfOneDollars=remainingAmount/100;
	remainingAmount=remainingAmount%100;
	int numberOfQuarters=remainingAmount/25;
	remainingAmount=remainingAmount%25;
	int numberOfDimes=remainingAmount/10;
	remainingAmount=remainingAmount%10;
	int numberOfNickels=remainingAmount/5;
	remainingAmount=remainingAmount%5;
	int numberOfPennies=remainingAmount;
	
	System.out.println("Your amount "+amount+" consists of");
	System.out.println("	"+numberOfOneDollars+" dollars");
	System.out.println("	"+numberOfQuarters+" quarters");
	System.out.println("	"+numberOfDimes+" dimes");
	System.out.println("	"+numberOfNickels+" nickels");
	System.out.println("	"+numberOfPennies+" pennies");
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值