Java循环我无法弄清楚 [英] Java loops I cant figure out

查看:80
本文介绍了Java循环我无法弄清楚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have 3 tasks I need to output. (The other comments are instructions to me). The 3 tasks are next to the first 3 asterisks. Can you assist me again please? Here it is:

* a for loop nested inside another for loop
* a while loop
* a do-while loop

*****************************************************************************************/

package prg420week3_codingassignment;

public class PRG420Week3_CodingAssignment {

public static void main(String[] args) {

// The following code should print asterisks: 1 on line 1, 2 asterists on line 2,
// 3 on line 3, 4 on line 4... for as many lines as the variable linesOfAsterisks.
// To do this, we can use 2 nested for loops. The first for loop is coded for you.
// You will need to add another for lop, NESTED INSIDE the first, that prints
// a certain # of asterisks based on the # of times the loop code has been executed.
// The result should look like this:
// *
// **
// ***
// ****
// *****
// etc.
int linesOfAsterisks = 5;
for (int i = 1; i <= linesOfAsterisks; i++) { // for each line...

// LINE 1. ADD A NESTED FOR LOOP THAT DISPLAYS ONE ASTERISK ON LINE 1, TWO ASTERISKS ON LINE 2, 3 ASTERISKS ON LINE 3, ETC.

System.out.println();
}

//////////////////////////////////////////////////////////////////////
// Add a while or do-while loop that displays the numbers from 10 to 1 in that order, like so:
// 10
// 9
// 8
// 7
// ...
// 1
//////////////////////////////////////////////////////////////////////


int num=10;

//LINE 2. ADD A LOOP THAT DISPLAYS NUMBERS 10 TO 1 IN DECREASING ORDER (HINT: DECREMENT OPERATOR)



///////////////////////////////////////////////////////////////////////
// Write a loop that adds 7s one at a time until the sum becomes > 157.
// Then print out both the sum and the number of 7s that were aded.
// Write a while or do-while loop, whichever you think is most appropriate.
//////////////////////////////////////////////////////////////////////////

int sum = 0;
int numberOfSevens = 0;

//LINE 3. ADD ANOTHER LOOP THAT ADDS 7s UNTIL SUM > 157. THEN DISPLAY SUM AND NUMBER OF SEVENS ADDED.

}





我的尝试:



我甚至无法开始这个。我可以请一些帮助。



What I have tried:

I can't even begin this. I could use some help please.

推荐答案

引用:

我不能甚至开始这个。我可以使用一些帮助。

I can't even begin this. I could use some help please.



从Java文档开始,关于循环,重读课程,查找教程,如果你不能设置任何东西,请与你的老师谈谈。 br $> b $ b

我们不做你的家庭作业。

HomeWork不会测试你乞求别人做你的工作的技巧,它是设置的让您思考并帮助您的老师检查您对所学课程的理解以及您应用这些课程时遇到的问题。

你的任何失败都会帮助你的老师发现你的弱点并设定补救措施。

你的任何失败都会帮助你了解什么有效,什么无效,被称为'试错'学习。

所以,试一试,重读课程并开始工作。如果您遇到特定问题,请展示您的代码并解释这个确切的问题,我们可能会提供帮助。


Start by the Java documentation about loops, reread your lessons, find a tutorial, if you can't device anything, have talk with your teacher.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.


Java™教程 [ ^ ]


这篇关于Java循环我无法弄清楚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆