大家下午好,我试着解决这个问题但是我坚持第一次循环 我必须做的原始条件是
Consider the following algorithm:
for ( i = 1; i<= 1.5n; i++)
print i
for ( i = n; i >= 1; i--)
print i
(a) What is the output when n = 2, n = 4?
(b) What is the time complexity?
我的代码看起来像这样
public class HelloWorld1 {
public static void main(String[] args) {
int n = (2);
for (int i=1; i<= 1.5 * n; i++)
{
for ( i = n; i=>1; i--)
}
{
System.out.println(i);
然而我收到错误
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token ">", delete this token
Syntax error on token ")", EmptyStatement expected after this token
at HelloWorld1.main(HelloWorld1.java:11)
我似乎无法弄清楚,也许你可以帮助我
答案 0 :(得分:1)
您的括号放置不正确。
这样做:
for (int i=1; i<= 1.5 * n; i++)
{
System.out.println(i);
for ( i = n; i>=1; i--)
{
System.out.println(i);
}
}