Write a program to display from 50 to 1 using For loop.
Answers
Answer:
class Numbers{
public static void main (String ar []){
for(int I=50;I>=1;i--){
System.out.println(I);
}
}
}
Logic:-
- Run for loop from 50 to 1 with decrement value -1
- Print the value of I loop
Answer:
//To Write A Program In Java to display numbers from 50 to 1
import java.io.*;
import java.lang.*;
class Name
{
public static void main(String args[])throws IOException
{
int i;
InputStreamReader reader = new InputStreamReader (System.in);
BufferedReader input = new BufferedReader (reader);
System.out.println("numbers from 50 to 1 are :-");
for (i =50; i >=1; i--)
{
System.out.println(i);
}
}
}
the "//_ _ _" is the remark of the program. Java interpreter simply ignores this statement.
here, we've used "System.out.println" command this prints all the individual sentences in next line.
*This program is in Java, since java is the most used programming language I hope this would help you. *
[NOTE :
- In order to run the program, you'd be needing command prompt or blueJ .
- Then, save the program with the name of the class name (it is compulsory).
- and add an extension of .java to the name of the file you save
]