This program is supposed to ask the user to input a number and the print will read out the factorial. This code is wrong how do I fix it? Maybe not add much just jumbled up variables? Help! This was given to me created in BLUE J software

i know the reader should equal the number
and for (x=number, x<=1;x++) but im not sure..

import java.io.*;
import java.util.*;
class Problem3
{
public static void main(String args[])
{
Scanner aReader = new Scanner(System.in);
System.out.print("Enter an integer you want to find the factorial for ");
int a = aReader.nextInt();

int fact=1;

for (inti=1;1<=a;i++)
fact=fact*i;
{
System.out.println(fact);
}
}
}

Recommended Answers

All 2 Replies

You have inti it should be int.

and 1<=a should be i<=a, and I rearranged the braces as well.

for (inti=1;1<=a;i++)
{
fact=fact*i;
}
System.out.println(fact);

this is what it should be:

for (int i = 1; i <=a; i++)
{
fact=fact*i;
}
System.out.println(fact);

thank you so much!!!!!!! it works

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.