What's new

Closed How to do this?

Status
Not open for further replies.

Great Commander

Forum Veteran
Joined
May 21, 2017
Posts
1,140
Reaction
2,209
Points
590
Paano po ba gawin to sa Java using JOptionPane?

Create a program that will display the factorial of a given input (integer).
sample:
input=5
output= 1x2x3x4x5=120.
 
Last edited:
Updated!
Male pla output una kong algorithm!
Try this!


var input as integer;
var answer as integer;
var product as integer;
var output as String;

console.in = input; //put inputstream here

product = 1;
answer = 1; // set value to 1
output = " output = " + product; // set first String msg.

for loop(var init=1; init < input; init++)
answer = answer + 1;
output = output + "x" + answer; //concat
product = product * answer;
end loop


console.out = output + "=" + product //concat



Ikaw na bahala convert n2 java syntax.
Kung my bug man paglarauan mu lang tsaka edit edit mu yung variables ko & values.
 
Last edited:
var input as integer;
var answer as integer;
var output as String;

console.in = input; //put inputstream here

input = 0;
answer = 0; // set value to 0
output = " output = 1"; // set first String msg.

for loop(var init=1; init<=input; init++)
answer = (answer + init) * answer;
output = output + "x" + answer; //concat
end loop

console.out = output + "=" + answer;//concat


Ikaw na bahala convert n2 java syntax.
Kung my bug man paglarauan mu lang tsaka edit edit mu yung variables ko & values.



Nostalgia!
Parang nung College time ko lang!
Salamat ng marami sir!
 
var input as integer;
var answer as integer;
var output as String;

console.in = input; //put inputstream here

input = 0;
answer = 0; // set value to 0
output = " output = 1"; // set first String msg.

for loop(var init=1; init<=input; init++)
answer = (answer + init) * answer;
output = output + "x" + answer; //concat
end loop

console.out = output + "=" + answer;//concat


Ikaw na bahala convert n2 java syntax.
Kung my bug man paglarauan mu lang tsaka edit edit mu yung variables ko & values.



Nostalgia!
Parang nung College time ko lang!

sir always 0 ang answer. mo initial value ni answer is 0. which minultiply mo.

using my brain.apk pala
 
try {
int num = Integer.parseInt(JOptionPane.showInputDialog("Please enter a number"));
int factorial=1;
System.out.println("Number inputted : "+num);
System.out.print("Output : ");
for(int x=1;x<=num;x++){
factorial =factorial*x;
String sign = (x == num) ? "=":"x";
System.out.print(x+" "+sign+" ");
}
System.out.println(factorial);

} catch (NumberFormatException e) {
System.out.println("The data you inputted is not a number.");
}

Copy paste mo nalang yan.
NOTE: Mag-aral ng mabuti para may matotonan.
 
try {
int num = Integer.parseInt(JOptionPane.showInputDialog("Please enter a number"));
int factorial=1;
System.out.println("Number inputted : "+num);
System.out.print("Output : ");
for(int x=1;x<=num;x++){
factorial =factorial*x;
String sign = (x == num) ? "=":"x";
System.out.print(x+" "+sign+" ");
}
System.out.println(factorial);

} catch (NumberFormatException e) {
System.out.println("The data you inputted is not a number.");
}

Copy paste mo nalang yan.
NOTE: Mag-aral ng mabuti para may matotonan.

advance programmer. using try cartch method. error handling style. very good practice. i recommend this.
 
Salamat ng marami sir!

sir always 0 ang answer. mo initial value ni answer is 0. which minultiply mo.

using my brain.apk pala

Updated!
Male pla output una kong algorithm!
Try this!


var input as integer;
var answer as integer;
var product as integer;
var output as String;

console.in = input; //put inputstream here

product = 1;
answer = 1; // set value to 1
output = " output = " + product; // set first String msg.

for loop(var init=1; init < input; init++)
answer = answer + 1;
output = output + "x" + answer; //concat
product = product * answer;
end loop


console.out = output + "=" + product //concat


Ikaw na bahala convert n2 java syntax.
Kung my bug man paglarauan mu lang tsaka edit edit mu yung variables ko & values.
 
init < input;
if init = 4 and input = 4 parang false ang statement ata.
Updated!
Male pla output una kong algorithm!
Try this!


var input as integer;
var answer as integer;
var product as integer;
var output as String;

console.in = input; //put inputstream here

product = 1;
answer = 1; // set value to 1
output = " output = " + product; // set first String msg.

for loop(var init=1; init < input; init++)
answer = answer + 1;
output = output + "x" + answer; //concat
product = product * answer;
end loop


console.out = output + "=" + product //concat


Ikaw na bahala convert n2 java syntax.
Kung my bug man paglarauan mu lang tsaka edit edit mu yung variables ko & values.
 
Status
Not open for further replies.

Similar threads

Back
Top