java - Applying the use of Functions and Procedures -
public static void main (string[] args) { scanner sc = new scanner(system.in); int number; system.out.println("enter number find factorial of it: "); number= sc.nextint(); int factor=1; if (number<0 && number>10) { system.out.println("invalid!! number has between 1 , 10"); } for( int x=1; x<=number; x++ ) { factor = factor*x; system.out.println("the factorial of "+number+" = " +factor); } }
can u check code @tnt? tell me if that's u wanted me do
here possible solution:
scanner sc = new scanner(system.in); int number; system.out.println("enter number find factorial of it: "); number= sc.nextint(); int factor = 1; // edit status numbers fall outside range 0-10 cause error // message display if (number < 1 || number > 10) system.out.println("invalid!! number has between 1 , 10"); else { for( int x=1; x<=number; x++ ) { factor = factor*x; } system.out.println("the factorial of "+number+" = " +factor); }
java bluej
No comments:
Post a Comment