In: Computer Science
Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9
import java.util.Scanner;
public class StringNumber {
public static void main(String[] args) {
System.out.println("Enter Input:
");
Scanner sc = new
Scanner(System.in);
String str=sc.nextLine();
boolean flag=true;
//iterating through each
character
for(int i=0;i
if(!Character.isDigit(str.charAt(i))) {
flag=false;
break;
}
}
if(flag)
System.out.println("Yes");
else
System.out.println("No");
}
}