Reputation: 17
I’m new to programming. I am to make a code that squares the integer. The rules is that:
Below is my desired result:
Input:
1
Output:
001
004
009
016
025
Below is my attempted code but it is not working.
int start=input.nextInt();
for(int i=5; i <=5; i++; start++){
num[i]= start*start;
}
for (i=0; i<num.length; i++){
System.out.println(“%03d\n”, num[i]);
}
}
}
Upvotes: 0
Views: 48
Reputation: 37
inputNum = sacnner.nextInt();
int loopTimes = 0;
While(loopTimes < 5 , loopTimes++){
System.out.println("%30d\n", inputNum*inputNum);
inputNum += 1
}
Upvotes: 0
Reputation: 479
Maybe you are looking for something like this. Ideone link https://www.ideone.com/IzO18y
import java.util.*;
import java.lang.*;
import java.io.*;
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
for(int i=1;i<=5;i++){
System.out.printf("%03d\n",n*n);
n+=1;
}
}
}
Upvotes: 2