Printing numbers in a pyramid pattern


Homework2
Note: Submit your work (upload the .java source code files ONLY, not the compiled .class files!) through the “Homework2” link on Brightspace. You may submit an unlimited number of times; we will only grade the last/latest submission attempt, but be sure to attach all of your files to each submission attempt. Be sure to include your name and Stony Brook ID number in a comment at the beginning of each file that you submit.
Due: Thursday, October 10, 11:59pm Total: 25 points (5 points per problem)
Submission Instructions: Name your java classes for this assignment as:
Problem1: Pyramid.java
Problem2: Interests.java
Problem3: LongestCommonPrefix.java Problem4: PerfectNumber.java Problem5: ArmstrongNumbers.java
1. Pyramid.java: (Printing numbers in a pyramid pattern) Write down a program in Java with a nested for loop that prints the following output (powers of 2) for any number of lines:
Here is a sample run:
Enter the number of lines: 8 Output:
1
121 12421 1248421
1 2 4 8 16 8 4 2 1
1 2 4 8 16 32 16 8 4 2 1
12 4 816326432168 4 2 1 124 81632641286432168 4 2 1
2. Interests.java: (Financial application: comparing loans with various interest rates) Write a program that lets the user enter the double loan amount and loan period in number of years (int) and displays the monthly and total payments for each interest rate starting from 5% to 8%, with an increment of 1/8.
   Here is the sample run:
Loan amount: 10000.00
Number of years: 5
Interest Rate Monthly Payment 5.000% 188.71
Total Payment
11322.74

5.125% 189.28 5.250% 189.85 ...
7.875% 202.16 8.000% 202.76
11357.13 11391.59
12129.97 12165.83
𝑑𝑜𝑢𝑏𝑙𝑒 𝑚𝑜𝑛𝑡h𝑙𝑦𝐼𝑛𝑡𝑒𝑟𝑒𝑠𝑡𝑅𝑎𝑡𝑒 = 𝑎𝑛𝑛𝑢𝑎𝑙𝐼𝑛𝑡𝑒𝑟𝑒𝑠𝑡𝑅𝑎𝑡𝑒 / 1200 ;
𝑑𝑜𝑢𝑏𝑙𝑒 𝑚𝑜𝑛𝑡h𝑙𝑦𝑃𝑎𝑦𝑚𝑒𝑛𝑡 = 𝑙𝑜𝑎𝑛𝐴𝑚𝑜𝑢𝑛𝑡 ∗ 𝑚𝑜𝑛𝑡h𝑙𝑦𝐼𝑛𝑡𝑒𝑟𝑒𝑠𝑡𝑅𝑎𝑡𝑒 / (1 − (𝑀𝑎𝑡h.𝑝𝑜𝑤(1/(1 + 𝑚𝑜𝑛𝑡h𝑙𝑦𝐼𝑛𝑡𝑒𝑟𝑒𝑠𝑡𝑅𝑎𝑡𝑒),𝑛𝑢𝑚𝑏𝑒𝑟𝑂𝑓𝑌𝑒𝑎𝑟𝑠 ∗ 12))); 𝑑𝑜𝑢𝑏𝑙𝑒 𝑡𝑜𝑡𝑎𝑙𝑃𝑎𝑦𝑚𝑒𝑛𝑡 = 𝑚𝑜𝑛𝑡h𝑙𝑦𝑃𝑎𝑦𝑚𝑒𝑛𝑡 ∗ 𝑛𝑢𝑚𝑏𝑒𝑟𝑂𝑓𝑌𝑒𝑎𝑟𝑠 ∗ 12; 𝑆𝑦𝑠𝑡𝑒𝑚.𝑜𝑢𝑡.𝑝𝑟𝑖𝑛𝑡𝑓("%.3𝑓%% %.2𝑓 %.2𝑓\𝑛",𝑎𝑛𝑛𝑢𝑎𝑙𝐼𝑛𝑡𝑒𝑟𝑒𝑠𝑡𝑅𝑎𝑡𝑒, 𝑚𝑜𝑛𝑡h𝑙𝑦𝐼𝑛𝑡𝑒𝑟𝑒𝑠𝑡𝑅𝑎𝑡𝑒, 𝑡𝑜𝑡𝑎𝑙𝑃𝑎𝑦𝑚𝑒𝑛𝑡);
3. LongestCommonPrefix.java: Write a program in Java that prompts the user to enter two strings and display the largest common prefix of the two strings. If there are no common prefix between the two entered strings display a message which tells the user that the two string doesn’t have a common prefix.
Here are some sample run:
Enter the first string: Atlanta
Enter the second string: Macon
Atlanta and Macon have no common prefix.
Enter the first string: Welcome to Java
Enter the second string: Welcome to programming
The common prefix is: Welcome to
Note: The prefix actually includes the space after ‘to’ as well
Enter the first string: I love coffee Enter the second string: I love Java The common prefix is I love
4. PerfectNumber.java: A positive integer is called a perfect number if it is equal to the sum of all of its positive divisors, excluding itself. For example, 6 is the first perfect number because 6 = 3 + 2 + 1. The next is 28 = 14 + 7 + 4 + 2 +1. Write a program that asks the user for an upper limit and prints all the perfect numbers up to that limit.
Here is a sample run:
Enter the upper limit: 10000
The perfect numbers below 10000 are: 6 28 496 8128.

5. ArmstrongNumbers.java: An Armstrong number is an n-digit integer such that the sum of the 𝑛𝑡h power of its digits is equal to the number itself. For example, 371 is an Armstrong number because 33 + 73 + 13 = 371 (371 is a 3-digit number). 8208 is an Armstrong number because 84 + 24 + 04 + 84 = 8208 (8208 is a 4-digit number). Write a program that asks the user for a lower limit and an upper limit and prints all the Armstrong numbers up to that limit.
Here are some sample runs:
Enter the lower limit: 10
Enter the upper limit: 1000
The Armstrong numbers between 10 and 1000 are: 153 370 371 407
Enter the lower limit: 8000
Enter the upper limit: 20000
The Armstrong numbers between 8000 and 20000 are: 8208 9474
Enter the lower limit: 25000
Enter the upper limit: 100000
The Armstrong numbers between 25000 and 100000 are: 54748 92727 93084

【四轴飞行器】非线性三自由度四轴飞行器模拟器研究(Matlab代码实现)内容概要:本文围绕非线性三自由度四轴飞行器的建模与仿真展开,重点介绍了基于Matlab的飞行器动力学模型构建与控制系统设计方法。通过对四轴飞行器非线性运动方程的推导,建立其在三维空间中的姿态与位置动态模型,并采用数值仿真手段实现飞行器在复杂环境下的行为模拟。文中详细阐述了系统状态方程的构建、控制输入设计以及仿真参数设置,并结合具体代码实现展示了如何对飞行器进行稳定控制与轨迹跟踪。此外,文章还提到了多种优化与控制策略的应用背景,如模型预测控制、PID控制等,突出了Matlab工具在无人机系统仿真中的强大功能。; 适合人群:具备一定自动控制理论基础和Matlab编程能力的高校学生、科研人员及从事无人机系统开发的工程师;尤其适合从事飞行器建模、控制算法研究及相关领域研究的专业人士。; 使用场景及目标:①用于四轴飞行器非线性动力学建模的教学与科研实践;②为无人机控制系统设计(如姿态控制、轨迹跟踪)提供仿真验证平台;③支持高级控制算法(如MPC、LQR、PID)的研究与对比分析; 阅读建议:建议读者结合文中提到的Matlab代码与仿真模型,动手实践飞行器建模与控制流程,重点关注动力学方程的实现与控制器参数调优,同时可拓展至多自由度或复杂环境下的飞行仿真研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值