Create Class Called Factorial Algorithm Which Will Compute / Print Factorial Of Integer Number On Screen
Dec 27, 2014
1)A factorial of a number X is equal to X*(X-1)*(X-2)*...*1.For example,3! is equal 3*2*1=6.Create a class called Factorial Algorithm which will compute and print the factorial of an integer number on the screen
2)Write a Java program to accept eight integers and a search element from the user and display whether the element is found or not.(Hint:use bubble sorting and binary search)
I am attempting to write a program that reads a nonnegative integer and computes and prints its factorial. So far I have: Java Code: import java.util.Scanner;
public class Chapter3point37 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int nonNegative = 5; int count=1; int product=1; int factor=1; System.out.println("Input a nonnegative integer: "); nonNegative = input.nextInt();
[code]...
how I should correctly prompt the user to input the values.
I'm working on some exercises and I'm having some problems with a method. I want to create a method to calculate the Factorial of an int number. I already wrote code that asks the user to input an int number and it calculates the Factorial, and it works fine
i.e.: if I input 5 it outputs
5! = 120
as it should. Here's the code:
import java.util.Scanner; public class Factorial1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int number; int total = 1;
[Code] ....
Now I want to make a method to re-use this code in other programs and I wrote this program:
public class TestClass { public static void main(String[] args) { System.out.print(factorial(5)); } public static int factorial(int x) { int total = 0;
[Code] ....
But when I run this program it outputs 0 instead of 120. What is wrong with this code as it compiles just fine but doesn't work as intended.
I'm suppose to be doing a factorial of a number within certain constraints (say a number between 5 and 10). I get the factorial easy enough but I'm getting it for every number no matter what I put in.
textio is used instead of scanner for our class.
Java Code:
public class Factorial { public static void main(String[] args) { int max = 0; int x = 0; long y = 0;
[Code] .....
Ideally I should be able to put in a number outside the range and the program will do nothing until I put a number in with the correct value.
I'm trying to learn Java and my current project is to write a short program to determine the factorial of a number entered by the user. I haven't looked. There may be a method that will do it, but I want to use a for loop specifically.
What I have compiles just fine. I'm actually pretty thrilled just with that. Here is what I have:
class factorial { public static void main( String[] args) { Scanner scan = new Scanner(System.in ); int num; int product = 1;
It was quite recently that Data Structures was introduced to me, so I started out writing some iterative programs recursively.I found some strange output which shouldn't have come out but if you take a look at these three codes
long factorial(long n) { if(n == 1) { return 1; } else { result = n*factorial(n-1);
[Code] ....
These are three versions of the code, achieving the same objective of obtaining a given number and returning the factorial, but in spite of the changes made to the code, they produce the same result. I needed a reason as to why it is so? I tried to dry run all the codes but at some point or the other I got confused, and had to start all over again and couldn't come up with a proper result.
Create a method called mirrorImage, which takes two integer arrays as input parameters. You may assume that the two actual parameters have the same length. Your method should return true if the arrays are the reverse of each other. Otherwise mirrorImage should return false.
Examples:
data1:{1,2,3} data2:{3,2,1} ==> true
[code].....
I'm pointing a place outside of the array or something
I need to work on this "Dice" program. I've done it twice already. I've also been pouring over examples on here and elsewhere online, but none of them exactly match what I'm doing, as they all say "Pair of Dice".Mine says: "Create a class called Dice to represent a SINGLE cube". It should have a method called roll() that randomly selects a number from 1-6 for the value of the dice."
It has to use java.util.random, not math.java, and it has to have numberShowing:int, roll():int, and main() all in it.The last part reads "Create a test main method for the Dice class that creates a dice and rolls it many times. Can you keep track of how many times a number comes up? Describe how or implement it in the program." I have started at this computer for hours, and read as much info as I can.
I have to write a program that inputs a 5 digit integer from the keyboard and prints if the input number is a palindrome or not. I got it to work, but when my result prints it says "0 is a palindrome" or "0 is not a palindrome". How can I get rid of the 0 and replace it with the number input by the user?
import java.util.Scanner; public class Palindrome { public static void main(String[] args) { int number; int digit; int temp;
i am trying to write a coin program:Write a class called Coin which will be used by a program called CountFlips.
1. The class, is an object created from this program. It is composed of data values and methods. It should contain a main method and should output the number of flips done (an integer that will be read from the user), the number of heads and tails that occur.
2. The CountFlip class will flip a coin multiple times and counts the number of ‘heads’ and ‘tails’ that result. This class should have a method called flip() of type void; a method called isHead() of type Boolean and a toString() method that will return the current face of the coin as a string.
So i created 2 classes, one called Coin.java & the other CountFlips.java,
PHP Code: package test; public class Coin { private final int heads = 0; private final int tails = 1; private int facetype; private int flips;
We have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Compute recursively (no loops or multiplication) the total number of blocks in such a triangle with the given number of rows.
We have to create a program called MyStack.In Push: Add one element at the end of the buffer.In Pull: Remove one element from the end of the buffer. In isEmpty: Should check if the list is empty or not and return the result as a boolean variable.
I am totally confused, I wrote the buffer and the array, but how do i add an remove element from the buffer?How do i add an element? What Statement do i Use?
Java Code: public class MyStack<T> implements Stack<T> { private final T[] ringbuffer; int index = 0; int last;
Write a program that will read two numbers and an integer code from the keyboard. The value of the integer code should 1, 2, 3, 4. If the value of the code is 1, compute the sum of the two numbers. If the code is 2, compute the difference (first number minus second). If the code is 3, compute the product of the two numbers. If the code is 4, and the second number is zero, compute the quotient (first divided by second). If the code is not equal to 1,2,3,4, display an error message. The program is then to display two numbers, the integer code and the computed result to the screen
here is the code that I have so far:
public static void main(String[] args) { Scanner read = new Scanner (System.in); int num1, num2, code, sum; System.out.println("Please enter a number"); num1 = read.nextInt();
I want to build a class that takes a JTable and previews on screen how it will be printed on the default printer. This is what we use to call as "Print Preview", just like MS Word, Excel, etc. As we already know Java does not support this functionality out-of-the-box.
Based on some examples I've found googling I built two classes. The first one TestPreview.java justs shows the JTable and the second one PrintPreview.java previews how the JTable will be printed on the printer.
I have two buttons to go through the pages, "PREV" and "NEXT" and "Print' button to print the JTable. My problem is that when my JTable has too many rows and spans in more than one page PrintPreview does not work. It shows the same page again and again. Also, it does not show the entire JTable data, but only some of them and I can't figure out why.
how to create a genetic algorithm.I made this class that Is supposed to Generate the chromes or Possible solutions of the program. Im pretty sure It doesn't have any syntax error and I went over the logic a couple time yet Im getting a NumberFormatException Exception Error. What this error means nor why am I getting it. Here's my code:
/* Contains the genes or possible solutions to the problem */ public class Genes { /* Each element is a binary number that corresponds to index number they have been assigned to, these are the possible genes * The last 4 elements in the array represent + - * / correspondingly */ private String[] encodedNumbers = {"0000", "0001", "0010", "0011","0100", "0101", "0110","0111","1000","1001","1010","1011","1100","1101"};
I am making a simple battleship program, you have the menu and click Start to get the board with the bombs (4 buttons as of now) Each button has either a bomb or a defualtbutton. I created my button so it can't be unselected. The problem is I have the button in a Class.java and I want that to close in a period of time. What do you recommend using?
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package battleship; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.GridBagLayout;
[code]....
I can call the clas in my main jFrame but I want to close the class after a certain time.
Write an instance method, contains, that has one explicit parameter of type Rectangle. The method should return true if every point of the rectangle determined by the explicit parameter is on or within the rectangle determined by the implicit parameter. It should return false otherwise.
My java class doesn't execute a shell sript, I had given the java io file permission read and execute over the script shell to the user who execute the java class, also I executed the script shell in the console each RAC server using oracle user session and the srcript shell works. My team DBA told me that " The user server process is oracle". My script shell resides in all RAC server file system the last result looks as follows:
/home/mydir/dir2/mybin/compacta_archivo.sh No Funcionando!! java.io.IOException: /home/gi91591/reppostpago/bin/compacta_archivo.sh not found
[Code]....
of course, the script file exist on my file system, it has the suitable permission as the test result i got each time I executed on the console. My Oracle version is 11.2.0.3.0 on Rac ASM.
I have searched for totalPay is always 0 and the responses are not related to my problem (that I can tell).This is a class assignment and I have other questions besides why the method is not working.
Here are the instructions: Create class Employee which contains a String variable Employee Number, a String variable Employee Name, an integer Hours Worked, and a double Pay Rate. Create get and set methods for each variable. Provide method "totalPay" which calculates and returns the total pay by multiplying the hours worked by pay rate. Use figure 8.12 as an example of an object with get and set methods.
Unlike other examples of this type question online this one has Employee Number as a String variable. The book is How to Program Early Objects by Deitel 9th edition.We have instructions to do only what she has told us too. At this point it is objects and getter and setter methods. It is only the beginning of week 2.
ON THE LINES WHERE I HAVE QUESTIONS I AM COMMENTING IN ALL CAPS. NOT SHOUTING, JUST TRYING TO MAKE IT EASIER
package test11; import java.util.Scanner; public class Test11 { public static void main(String[] args) { Scanner input = new Scanner(System.in);
[code]..
Essentially I cannot figure out how to get the method getTotalPay to be called by the Scanner and do the math. I also have this random bracket problem that showed up about an hour ago.
The concept I don't get is that if I omit this.employeeNumber =id; etc. I error all over the place. If I change it to this.employeeeNumber = employee Number Netbeans tells me it is assigning itself to itself, which I know. When I try to use id instead of employeeNumber I get errors all over. If i remove "this" from it the same happens. why in public class employee I have to change to those values (id, name, etc) in the construct and set them again? I don't see where or how they can be used, so why do i have to do it?
So I was just wondering if it's possible to create a program with JAVA that uses an algorithm to summarize data inputed. I've never done something like this before, If this is not possible with Java is it possible with C++ or any other language??
Basically the class is supposed to have a static variable that keeps track of the number of companies (numberOfCompanies) that have been created and a static method that returns the value of this variable. I need to have a constructor and a method to addEmployee, a method to printCompany, and a toString method. The addEmployee method will check that there is only 1 salesperson, 2 designers, and 4 manufacturing persons at a time and will check that there are no more than 7 employees of the company.
The addEmployee method will return a String indicating what the error is (i.e. "There is already a sales person in this company") or a null if the employee was added. If attempting to name a third company, an error message will be shown. what i have so far but my print company mmethod returns null company class :in which i am obliged to use inputdialog because it says that it cannot return void when i use the showmeassage diaolog.
company class:
import java.util.ArrayList; import javax.swing.JOptionPane; public class Company { private ArrayList<Employees> list ; private static int numberOfCompanies;
[Code] ....
error message when print button is clicked:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent at javax.swing.JOptionPane.createInternalFrame(Unknown Source) at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source) at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)
I am working on a little nothing project, but I wanted to create a random number generator for a silly game where the user guesses the number.I have used google, but they are using LOG statements, what it does.