In Java programming language
11.Create the code for a for loop to print the numbers 1 through 5 inclusive vertically so the output is
1
2
3
4
5
11b What is the output of the following OUTPUT
int i=3;
while(int i >0)
{
System.out.println(i);
i--;
}
11c What is the output of the following OUTPUT
for(int i=3;i<10;i++)
System.out.println(3*i);
11d Create the line of code to print the numbers 10 through 1 decreasing by 1 each time
11e Create the line of code to print Your first name 5 times vertically
Answer1:
public class Main
{
public static void main(String[] args)
{
for(int i = 1; i <= 5; i++)
{
System.out.println(i);
}
}
}
Explanation: There is simple for loop used from 1 to 5 and incremented by1.
Answer2: 3
2
1
Explanation: i starts from 3 and decremented by 1 every time.
Answer3:
9
12
15
18
21
24
27
Explanation: loop starts from 3 and less than 10, each loop will multiply by 3.
Answer4:
public class Main
{
public static void main(String[] args)
{
for(int i = 10; i >= 1; i--)
{
System.out.println(i);
}
}
}
Explanation: i starts from 10 to greater than
equal to 1 and decremented by 1 every time
Answer5 :
public class Main
{
public static void main(String[] args)
{
for(int i = 1; i <= 5; i++)
{
System.out.println("First Name");
}
}
}
Explanation: Loop starts from 1 to less than equal to 5 and incremented by. Each iteration will print First name.
Get Answers For Free
Most questions answered within 1 hours.