Need help in java Thank you Write a recursive voided functio
Need help in java. Thank you
Write a recursive voided function name printSquares that takes an integer parameter and print to the screen the sequence from 0 to that number and their squares. Make sure you add pre and post conditions to your method.Solution
import java.util.Scanner;
public class SquareFunction {
static int count = 0;
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
System.out.print(\"Enter any number\");
int no = sc.nextInt();
printSquare(no);
}
static void printSquare(int no){
if(no<0){
System.out.println(\"exiting no is negative\");
}
else{
while(count<=no){
System.out.println(\"Square of \"+count+\" is \"+(count*count));
count++;
}
}
}
}
