Write a programe to print squares of numbers 1 to 5
Hey guys answer quickly please
extra 2 points........
Share
Write a programe to print squares of numbers 1 to 5
Hey guys answer quickly please
extra 2 points........
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Verified answer
Required Answer:-
Question:
Solution:
This is an easy program. Here is the code.
It's written in Java.
public class Squares {
public static void main(String[] args) {
System.out.println("Squares of numbers from 1 to 5 are as follows...");
for(int i=1;i<=5;i++)
System.out.print(i*i+" ");
}
}
It's written in Python.
print("Squares of numbers from 1 to 5 are as follows..")
for i in range(1,6):
print(i**2,end=" ")
Output is attached.
Question:-
Answer:-
•Java Code:-
package Coder;
public class Square
{
public static void main(String ar[])
{
for(I=1;I<=5;I++)
System.out.println("Square of "+I+" is "+(Math.pow(I, 2)));
}
}
•Python Code:-
# Code written by:-
# @swetank232894
for I in range(1,6,1):
print("Square of ",I," is ",(I**2))
•Output attached