My issue
How to solve this problem
My code
import java.util.Scanner;
class Codechef
{
public static void main (String[] args)
{
// update your code below this line
int num;
Scanner scanner = new Scanner(System.in);
num = scanner.nextInt();
System.out.println(num);
if (scanner.hasNextInt()) {
num = scanner.nextInt();
// Calculate and print the square
int square = num * num;
System.out.println("The square of " + num + " is " + square);
} else {
System.out.println("Invalid input. Please enter an integer.");
}
// Close the scanner
scanner.close();
}
}
Learning course: Learn Java
Problem Link: CodeChef: Practical coding for everyone