Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help with this Computer Science assignment! (This is the Assighment) 1) F

ID: 3552239 • Letter: P

Question

Please help with this Computer Science assignment!


(This is the Assighment)


1) Factorials: The factorial of any positive integer N is the product of the positive integers from 1 to N. ie: 3! is 1 * 2 * 3 = 6.

2) Write a program which uses JOptionPane to take an integer input from the user. Use the integer to print the following pattern.
Sample Input: 3
Output:

1 12 123

Sample Input: 5 Output:
1
12

123 1234 12345

3) Using nested for loops, print a multiplication up to 10. Output
1*1 1*2 1*3 1*4 ... 1*10
2*1 2*2 2*3 2*4 .... 2*10

.
10*1 10*2 10*3
10*4 .... 10*10


(This is what I have so far)

import java.util.*;

import java.util.Scanner;

public class LabAssignment8 {


/**

* CS 110 Section

* Lab Assignment 8

**/

public static int factorial (int n)

{

double x = a*b*c;

return x;

}

public static void main(String[] args) {

//int c = add(2,3);

double x = product(1,2,3);

// part one

int p = 1;

int n;

for( int i = 1; i <= n; i++);

/**Scanner s = new Scanner(System.in);

//part 2

int N;

System.out.println("Please enter the number of lines you woud like:");

N = s.nextInt();

for(int i = 1; i <= N; i++);

{

for(int j = 1; j <= 1; j++);

{

System.out.print("*");

}

System.out.println();

}

//part 3

for( int x=1; x<10; x++);

{

for(int y=1; y<10; y++);

}

**/

}


}

If you could help me fill in the gaps I'd appreciate it! Thanks Again!

Explanation / Answer

import javax.swing.JOptionPane;

public class MyFactorials {
public static void main (String[] args) {
int Number = 0;
double Factorial = 0;
String userInput = "";

do {
userInput = JOptionPane.showInputDialog("Enter a number: ");
Number = Integer.parseInt(userInput);
} while(Number < 0);

while(Number <= 1) {
Factorial *= Number;
Number--;
}

if(Number == 0) {
Factorial = 1;
}

System.out.println("The factorial of " + userInput + " is " + Factorial);
}
}