In: Computer Science
How would I get this started:
Code a logic program that uses a for loop to call your method 5 times successively on the values 1 through 5. (i.e. it would display the val and it’s square…)
Java code for the given requirement:
public class Demo{
public static void main(String arg[]){
//Using for loop to call the method exactly five times for the values of 1 through 5
for(int i=1; i<=5; i++) {
//Calling the display square method
displaySquare(i);
}
}
private static void displaySquare(int i) {
//TODO Auto-generated method stub
//displaying the value and its square
System.out.println(i+" and it's square is "+i*i);
}
}
Output: