Write Numbers From 1 To 1000 But 5 By 5

Oct 10, 2014

I need to write a JAVA program and algorithm that writes the numbers from 1 to 1000. Then I ned to write another one that writes the numbers from 1 to 1000, but 5 by 5. ( example 5,10,15,20,25,30)....

View Replies


ADVERTISEMENT

How To Write First 30 Fibonacci Numbers

Jun 29, 2014

I want to write the first 30 Fibonacci numbers so wrote this script:

Java Code:

int num1 = 1;
int num2 = 1;
int num3;
String x = num1 + ", " + num2;
for (int i=1; i==28; i++){
num3 = num1 + num2;
x += ", " + num3;
num1 = num2;
num2 = num3;
}
System.out.println(x); mh_sh_highlight_all('java');

This script outputs this only: 1, 1

View Replies View Related

Write A Program That Find The Sum Of Two Numbers 62 And 99?

Jan 23, 2015

I have to write a program that find the sum of two numbers 62 and 99 and stores them in a variable named total. However, I have one error that I just can't get rid of and can't tell what it is. I'm using jGrasp and here's what it says:

Programming Challenge #5.java:14: error: class SumofTwoNumbs is public, should be declared in a file named SumofTwoNumbs.java
public class SumofTwoNumbs {
^
1 error
  ----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

and here: is my code:

import java.util.Scanner; 
/*
* 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.
*/
 /**
// This program has variable of several of the integer types.
public class SumofTwoNumbs {
public static void main(String[] args) {

[code]....

View Replies View Related

Write A Program That Takes Two Numbers And Multiplies Them

Jul 8, 2014

I am trying to write a program that takes two numbers and multiplies them. I got this idea from this running conversion program

import java.util.Scanner;
public class Convert
{
public static void main (String [] args)
{
Scanner reader = new Scanner (System.in);
double farenheit;
double celsius;

[code]...

i am getting a cant find symbol for the output = (alpha*beta) line..Also, am I using the reader object correctly ? hould I create two reader objects as there are 2 inputs needed?

View Replies View Related

Write Application That Display Numbers 1 To 4 On Same Line

Jul 22, 2007

I'm going to be taking an object oriented paradigm using java during intersession in a few months. I'm trying to brush up on it a bit. The problem is. Write an application that displays the numbers 1 to 4 on the same line, with each pair of adjacent numbers separated by one space. Write the program using the following techniques:Use one system.out.printLn statement.Use four system.out.print statement.Use one system.out.printf statement.

This is what i have so far .

Java Code: public class Display
{
public static void main(String [] args) {
System.out.print("1 ");
System.out.print("2 ");
System.out.print("3 ");
System.out.print("4 ");
System.out.println(" ");<----is that what that is supposed to look like, and where it goes?
System.out.printf(" %s %s %s %s ");????
}
} mh_sh_highlight_all('java');

i cant test this my console isn't working right, and i haven't finished my compiler install.

View Replies View Related

Write A Program That Prompts User For 3 Double Numbers

Feb 15, 2015

So i need to write a program that prompts the user for 3 double numbers x, y, z that outputs 2x^3 + 3y^5 + 3x^3y^2 +xyz with

(1) 4 digits precision
(2) with a ',' to separate thousands
(3) all digits of the result including the precision are put to 20 positions (from right to left)

I am not really sure what it is suppose to look like or how to start it.how to mix Math.pow with multivariable and printf.

View Replies View Related

Generating Random Number Between 1-1000

Oct 31, 2013

I am very new to programming. This is for a college assignment. It says in the brief of the assignment that we will need to convert Math.random to output a random number between 1-1000. How can I do this?

View Replies View Related

Program To Roll 1000 Times And Count How Many 7s Rolled

Nov 15, 2014

public class PairOfDice
{
private Die die1, die2;
public PairOfDice() {
die1 = new Die();
die2 = new Die();

[Code] .....

I am struggling with the final part of my code to get the dice to roll 1000 times and tell me how many times a 7 was rolled. I am getting these errors in jgrasp

----jGRASP exec: javac -g PairOfDice.java

PairOfDice.java:34: error: <identifier> expected
count = 0;
^
PairOfDice.java:35: error: illegal start of type
for (rep = 1; rep <= 1000; rep++) {

[Code] .....

22 errors

View Replies View Related

Roll Four Sided Die Between 100 And 1000 Times Depending On Input And Display Answer

Oct 29, 2014

I'm trying to get the program to roll a four sided die between 100 and 1000 times, depending on your input, and then displaying the answer.

public class Lab08
{
public static void main(String[] args)
{
int v1 =0, v2 = 0, v3 = 0, v4 = 0;
int n;
char response;
System.out.print("Enter number of rolls (100-1000): ");
 
[Code] ....

View Replies View Related

Opoly Game - Goal Of The Game Is To Reach Or Exceed Reward Value 1000

Mar 12, 2015

Opoly works this way: The board is a circular track of variable length (the user determines the length when the game app runs). There is only one player, who begins the game at position 0.

Thus, if the board length is 20, then the board locations start at position 0 and end at position 19. The player starts with a reward of 100, and the goal of the game is to reach or exceed reward value 1000. When this reward value is reached or exceeded, the game is over. When the game ends, your program should report the number of turns the player has taken, and the final reward amount attained.

In Opoly the game piece advances via a spinner - a device that takes on one of the values 1, 2, 3, 4, 5 at random, with each of the five spin values equally likely.

Although the board is circular, you should draw the state of the board as a single "line", using an 'o' to represent the current player position, and * represent all other positions. Thus if the board size is 10, then this board drawing:

**o******

means that the player is at location 2 on the board.

Here are the other Opoly game rules:

If your board piece lands on a board cell that is evenly divisible by 7, your reward doubles.

If you land on the final board cell, you must go back 3 spaces. Thus if the board size is 20, the last position is position 19, and if you land there, you should go back to position 16. (If the position of the last cell is evenly divisible by 7, no extra points are added, but if the new piece location, 3 places back, IS evenly divisible by 7, then extra points ARE added).

If you make it all the way around the board, you get 100 points. Note that if you land exactly on location 0, you first receive 100 extra points (for making it all the around), and then your score is doubled, since 0 is evenly divisible by 7,

Every tenth move (that is, every tenth spin of the spinner, move numbers 10,20,30,... etc.), reduces the reward by 50 points. This penalty is applied up front, as soon as the 10th or 20th or 30th move is made, even if other actions at that instant also apply. Notice that with this rule it's possible for the reward amount to become negative.

Here is the driver class for the game:

import java.util.*;
public class OpolyDriver{
public static void main(String[] args){
System.out.println("Enter an int > 3 - the size of the board");
Scanner s = new Scanner(System.in);
int boardSize = s.nextInt();

[Code] ....

heres the methods:

REQUIRED CODE STRUCTURE: Your Opoly class must include the following methods (in addition to the Opoly constructor) and must implement the method calls as specified:

playGame - The top-level method that controls the game. No return value, no parameters. Must call drawBoard, displayReport, spinAndMove, isGameOver.

spinAndMove - spins the spinner and then advances the piece according to the rules of the game. No return value, no parameters. Must call spin and move.

spin - generates an integer value from 1 to 5 at random- all equally likely. Returns an integer, no parameters.

move - advances the piece according to the rules of the game. No return value, takes an integer parameter that is a value from 1 to 5.

isGameOver - checks if game termination condition has been met. Returns true if game is over, false otherwise. No parameters.

drawBoard - draws the board using *'s and an o to mark the current board position. Following each board display you should also report the current reward. No return value, no parameters.

displayReport - reports the end of the game, and gives the number of rounds of play, and the final reward. No return value, no parameters.

View Replies View Related

Long Type Output File - Print Prime Numbers Between Given Range Of Numbers

Aug 22, 2014

I tried to create file and write the output of my program in it in java when i use WriteLong then the file does not contain long value, how I create this file my program is to print prime numbers between 500000 to 10000000

public class primenumber {
public static void main(String[] args) {
long start = 5000000;
long end = 10000000;
System.out.println("List of prime numbers between " + start + " and " + end);
for (long i = start; i <= end; i++) {
if (isPrime(i)) {
System.out.println(i);

[Code] ....

View Replies View Related

Generate 100 Numbers Using Arrays - Sort Even Numbers Into Separate Array And Display Both

Apr 24, 2014

I've just written a program that generates 100 numbers that range from 0 ~ 25 using arrays, the program calls another method that sorts the even numbers into a separate array and returns the array. I need it to display both arrays, however, when I run my program, the numbers of both arrays are mixed together, and I'm not sure how to separate them.

[ public class Array1
{
public static void main(String[] args)
{
int array [ ] = new int[100];
for (int i = 0; i < array.length; i++)
{
array[i] = (int) (Math.random() * 26);

[Code] .....

View Replies View Related

Print 2 Lists - 20 Random Numbers And Another List Without Duplicate Numbers

Feb 1, 2015

I'm trying to make a program that generates 20 random integers between 1 and 20 and then prints the list of random numbers to the screen. After that, I want to print a different list to screen with the same numbers from the first list only skipping any number that has been already printed to the screen. So two lists are printed to the screen. The first one has 20 random numbers. The second one has those same 20 numbers but only prints the numbers in the first list that aren't duplicated. So if m

y list of 20 random integers contains three 2s and two 14s, only one 14 and one 2 is printed to the second list. Currently, my code generates 20 numbers from 1 to 20 and stores those numbers in an array but I don't know how to print solve the second part of my problem. I don't know how to print the s different list only without duplicate numbers. As a result, my output is nothing because it doesn't print any number from the first list as oppose to skipping only duplicate one.

public void randomNum(){
System.out.println("Twenty random integers: ");
int max = 20; // max value for range
int min = 1; // min value for range
Random rand = new Random();
int[] all = new int[20];

[Code] ....

View Replies View Related

User To Enter 10 Numbers And At The End Prints Out Distinct And Non-repeated Numbers

Nov 23, 2014

I have to make a program that prompts the user to enter 10 numbers and at the end it prints out the distinct numbers and then the other numbers that weren't repeated...

I have the part where it prints out the distinct numbers but I stuck on how to make it print out the other numbers that didn't repeat...

import javax.swing.JOptionPane;
public class DistinctNumbers {
public static void main(String[] args) { 
String getInput;
int input;
int[] numbers = new int[10];

[Code] ....

View Replies View Related

Generate Two Arrays - One With All Positive Numbers And Another With Negative Numbers

Mar 10, 2015

Create an integer array with 10 numbers, initialize the array to make sure there are both positive and negative integers. Write a program to generate two arrays out of the original array, one array with all positive numbers and another one with all negative numbers. Print out the number of elements and the detailed elements in each array.

public class problem3 {
public static void main(String[]args){
int[] numbers = {1, 2, 3, 4, 5, -1, -2, -3, -4, -5};
for (int i = 0; i<numbers.length;){
if(i>0){
System.out.println(numbers);
}
else
System.out.println(numbers);
}
}
}

View Replies View Related

Generate Random Numbers Without Certain Numbers In Range

Jul 31, 2014

I tried out doing number (generated randomly) != (another number) but that does not work. If I for example want a number between 1 and 10, but I do not want the number 5, what can I do in order to make this happen?

View Replies View Related

List All Prime Numbers Between Two Entered Numbers

Oct 17, 2014

Program is to list all prime numbers between two entered numbers.

import java.util.Scanner;
public class question6 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter lower int:");
int x = input.nextInt();

[Code] .....

View Replies View Related

How To Write Key Listener

Jan 7, 2014

I want to make a program that will move a square to the left if you press "a", and to the right if you press "d". (Once I know how to do this I can figure out W and S for up and down by myself). What code would I use for doing that? Here is the program I have now. I used the oracle tutorial but it just shows how to handle for if ANY key is pressed.

This is what I used How to Write a Key Listener (The Java Tutorials > Creating a GUI With JFC/Swing > Writing Event Listeners)

Java Code:

import java.awt.BorderLayout;
import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class myGame extends JComponent {
public int x = 20;
public int y = 20;

[code]....

View Replies View Related

Write A Code Using The Stacks?

May 15, 2014

write a code using the stacks?i want the output to produce my name.

View Replies View Related

Read / Write Int Property

Feb 4, 2014

I am trying to do a read/write int property called currentQuestionIndex. This property is the index of the question currently selected, and the value of the property is 0 when a DrivingTest object is first created. I dont understand how to do this. I am not sure how to get the index of the current question. i was trying to use an iterator but i dont think i was doin it right. My question class that hold all my data
 
package cs320Labs.servlet;
 public class Question {
String description;
String answerA;
String answerB;
String answerC;
int correctAnswer;

[Code] ....

View Replies View Related

JSP :: Write Tags In HTML?

Mar 26, 2015

Is there anything wrong with writing JSP tags in psuedo-HTML? I've been writing tags in XHTML, but it would seem that XHTML could not be compliant with both an XHTML standard and the HTML5 standard.

View Replies View Related

Write Hashset To Txt Using Filewriter

Mar 23, 2015

I am trying to write a hashset to a text file. Normally, I have no issues with writing to txt as it is simple for me. However, in this case I am absolutely clueless.

A bit of background about the class: it is a hashset of ComputerScientist objects with 2 fields; name, and field of research (and yes, I know what I put to fill up the HashSet does not count, I was only trying to test to see if I could get this to work).

I know the basic setup to use filewriter to save strings to a txt, but I am getting confused with the HashSet element of it.

import java.util.HashSet;
import java.io.FileWriter;
import java.io.IOException;
/**
* Write a description of class ComputerScientistSet here.
*/
public class ComputerScientistSet {
private HashSet<ComputerScientist> computerScientistSet;

[Code] .....

View Replies View Related

How To Write Zip File Like Application

Feb 2, 2014

I want to write an application which stores files inside of itself, like a Zip file, but it will not be a zip or have the zip compression class.

View Replies View Related

GUI Button Write To File

Dec 8, 2014

I have created a program that allows a pizza shop to enter a customers orders (via 3 seperate panels of options), and calculate a total. Everything works just fine, and now we have to take it a step further and record the sale data in a .txt file (which will include the Crust Type, Toppings, and Extras).

I need to make it so that when a user clicks the calculate button, it also writes to a file (in this case, SalesRecords.txt). I have it all set up, but for some reason I can not get it to work. The error I get is:

"error: unreported exception FileNotFoundException; must be caught or declared to be thrown
PrintWriter outputFile = new PrintWriter(filename);

Here's my code: (the calculate button that I am working with is indicated by a comment)

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.text.DecimalFormat;
import java.io.*;
import java.io.BufferedWriter;

[I looked up the exception I got, and just so everyone knows I made sure that the file "SalesRecords.txt" DOES EXIST. It is in the same folder as my java and class files for this program. I even tried defining the absolute file path for SalesRecords.txt and that changed nothing.

View Replies View Related

JSP :: How To Write A Code In JavaScript

Jul 25, 2014

In my JSP file I need to rewrite the content of a <div> using Java script. <div> contains the JSP scriptlet tag.

View Replies View Related

Error When Trying To Write Files?

Feb 16, 2015

I'm trying to write information into a file using PrintWriter. The program complies correctly but when it get's to the following part of the program, an error is given. "Exception in thread 'main' java.io.FileNotFoundException" What is wrong with it?

System.out.print("Enter the filename:");
filename = kb.nextLine();
PrintWriter outputFile = new PrintWriter(filename);
outputFile.println(balance);
outputFile.print(item1+" "+item1Price);
outputFile.println(" "+item1Quantity);
outputFile.print(item2+" "+item2Price);
outputFile.println(" "+item2Quantity);
outputFile.print(item3+" "+item3Price);
outputFile.println(" "+item3Quantity);
outputFile.close();
System.out.println("Data written to the file.");

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved