My assignment is to Write an application that reads a non-negative integer and prints the factorial of the integer using the for loop. I am hopelessly lost and don't even know where to begin with this. Does anyone have any advise to get me started? Thank you
dylgod
0
Newbie Poster
Recommended Answers
Jump to PostBreak the project down into steps.
One step is to read in a non negative integer.
Write a java program to do that. Compile it and execute it. Come back when you have problems. Post the full text of the error messages and the program.Now look up the …
Jump to Post/* “PositiveInt.java” receives an integer greater than 0. In this program Exceptions are catched accordingly */ import javax.swing.*; public class PositiveInt{ static class NonNegativeException extends Exception{ public NonNegativeException(String msg){ super(msg); } } static void show(int x)throws NonNegativeException { if (x<0) throw new NonNegativeException("Negative integer is not valid."); …
Jump to Post/* Operation on DOS window: "PositiveInt1" receives a positive integer only. */ import java.util.*; public class PositiveInt1{ public static void main(String args[]){ int n=0; Scanner in = new Scanner(System.in); while(true){ try{ System.out.println("Input a non-negative integer:"); n = in.nextInt(); }catch(InputMismatchException e){ System.out.println("Your input is mismatched."); in.next(); continue; } …
All 12 Replies
NormR1
563
Posting Sage
Team Colleague
tong1
22
Posting Whiz
tong1
22
Posting Whiz
tong1
22
Posting Whiz
NormR1
563
Posting Sage
Team Colleague
tong1
22
Posting Whiz
dylgod
0
Newbie Poster
NormR1
563
Posting Sage
Team Colleague
dylgod
0
Newbie Poster
tong1
22
Posting Whiz
NormR1
563
Posting Sage
Team Colleague
tong1
22
Posting Whiz
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.