Counting Number Of Steps Throughout The Circle

Jan 27, 2015

The method public static int steps(int posts, int stride) calculates how many strides can be taken to get back to posts. Let's say if the method is (12, 4), it takes only three steps. Now let's say the method has parameters (12,5), so it should be (5, 10, 3, 8, 1, 6, 11, 4, 9, 2, 7, 12). My method works for such examplse as (12, 4) or (12,3) or (6,2)... but how can I figure out (12,5)?

Java Code:

public static int steps(int posts, int stride) {
int countSteps = 0;
int result = 0;
do {
result += stride;

[Code] ....

View Replies


ADVERTISEMENT

Counting Number Of Paragraphs In A Text?

Apr 19, 2014

How do I count the number of paragraphs using a separate method?

import java.util.*;
import java.io.*;
public class WordStats1 {
public static void main(String[] args) {
try {
Scanner input = new Scanner(new FileReader("data.txt"));
PrintWriter output = new PrintWriter(new FileOutputStream(

[code].....

View Replies View Related

Counting Number Of Paragraphs In A Text

Apr 19, 2014

Why my code wont compile the correct number of paragraphs .

import java.util.*;
import java.io.*;
public class WordStats1 {
public static void main(String[] args) {

[Code] ....

View Replies View Related

Counting Number Of Words From User Input

Jan 2, 2015

I tried the following code, OK:

Java Code:

String temp = "hi this sf hello is new what is this";
String[] cmd = temp.split("s");
int num = cmd.length;
System.out.println("number of words are: "+num); mh_sh_highlight_all('java');

However, when i get the input from user , i didnt get the expected result:

Java Code:

System.out.println("Enter the input string to count the words: ");
String[] cmd = new Scanner(System.in).next().trim().split("s");
int num = cmd.length;
System.out.println("number of words are: "+num); mh_sh_highlight_all('java');

Now Result for above code:

Enter the string to count the words:

hi this is new

words are: 1

View Replies View Related

Counting Number Of Bits For Char Representation?

Mar 14, 2014

i need to show that there are 16 bits for a char variable.

i tried converting it to an int and then apply the bitCount method but that gave an output of 3.

what method should i use?

View Replies View Related

Sorting Arrays And Counting Number Of Swaps

Nov 2, 2013

I need to modify modules used in the book that run a bubble sort, selection sort, and insertion sort on an integer array such that each module keeps a count of the number of swaps it makes.

How do I code for this?

Then we have to design an application that uses 3 identical arrays of at least 20 integers. That calls each module on a different array, and display the number swaps made by each algorithm.

View Replies View Related

Counting Total Number Of Searches - Calling Price Method

Apr 23, 2015

How would I program a counter that will return the total number of search, failed searches and correct searches. The second thing is how can a return the price of the search methods with out calling for it specifically. Here is my current code.

package stu.paston.program7;
import java.util.Scanner;
public class MainClass
{
public static void main(String[] args)
{
InventoryClass productData= new InventoryClass();

[Code] ....

View Replies View Related

Read Picture And Print Out Number Of Blocks - Counting In Multidimensional Array

Dec 19, 2014

I have to write a program that will read a picture and then print out the number of blocks inside it.

I have to read the picture as a binary matrix of the size r - c (number of rows times number of columns). The blocks are groups of one or more adjacent elements with the value 1.

- Blocks are built exclusively of elements with value 1
- Each element with value 1 is a part of some block
- Adjacent elements with value 1 belong to the same molecule.

We only take into account the horizontal and vertical adjacency but not diagonal.

INPUT:

In the first line of the input we have the integers r and c, separated with one space.
Then we have the r lines, where each contains s 0's and 1's.
The numbers inside the individual lines are NOT separated by spaces.

The OUTPUT only print the number of blocks in the picture.

Example:

INPUT:
7 5
01000
00010
00000
10000
01000
00001
00100

OUTPUT:
6

THIS IS WHAT I CAME UP SO FAR:

import java.util.Scanner;
class Blocks{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
char ch[][];
int rowNum=sc.nextInt();
int columnNum=sc.nextInt();

[Code] ....

View Replies View Related

Steps Class Is Not Being Run

Oct 10, 2014

My java project has got a jbehave story and steps class. when i run the test, an instance of the steps class is being created but the class is not actually run.

my steps class :

public class StepsDemo extends Steps {
int x, result = 0;
StepsDemo() {
System.out.println("steps class constructor : object created");

[code]....

and my Runner class :

public class RunnerDemo extends JUnitStories {
public RunnerDemo() {
super();
}
@Override
protected List<String> storyPaths() {

[code]....

View Replies View Related

While Loop To Perform Multiple Steps

Mar 20, 2014

Write a program that uses a while loop to perform the following steps: Comment by labelling each part: //Part A, //Part B, etc...

A.)Prompt the user to input 2 integers: firstNum and secondNum. Use 10 and 20.
B.)Output all odd numbers between firstNum and secondNum.
C.)Output the sum of all even numbers between firstNum and secondNum.
D.)Output the numbers and their square between 1 and 10.
E.)Output the sum of the square of odd numbers between firstNum and secondNum.
F.)Output all uppercase letters.

Again I am new to while loops and I am totally lost. I have just completed 8 other programs using if else statements and now trying to get the hang of loops.

import java.util.Scanner;
public class whileLoop {
public static void main(String[] args)

[code]...

View Replies View Related

EJB / EE :: Steps To Implement User Authentication?

Aug 1, 2014

I'm building a JavaEE 7 web app and I want to add user authentication. Although I haven't found a complete guide, via the resources I've gathered I think I'm quite close. I can't make it work though. In all honesty I don't understand ALL of the code yet, I'm using it though because it's supposed to work, it's from JavaEE 7 Recipes book.

I've created my database, set up the JDBC realm in GlassFish, added the persistence unit, created the entity classes, the backing bean, the ejb, called the EL expressions...

When I'm supposed to login it throws a "loginBean.username is unreachable" or something. I don't understand why, the inputText's value is supposed to go straight to the backing bean right?

View Replies View Related

EJB / EE :: Steps To Implement User Authentication

Aug 1, 2014

I've created my database, set up the JDBC realm in GlassFish, added the persistence unit, created the entity classes, the backing bean, the ejb, called the EL expressions...

When I'm supposed to login it throws a "loginBean.username is unreachable" or something. I don't understand why, the inputText's value is supposed to go straight to the backing bean right?

I know this is a very vague description but I can provide you with all the code you may want, it's simply I cannot think of anything to do right now since I'm not familiar with the methodology yet...

View Replies View Related

How To Do Nested Circle Dynamically

Feb 8, 2015

i'm trying to do a nested circle dynamically. i don't know whats wrong with my program ...

private Ellipse2D.Float doubleElip(int x1, int y1, int x2, int y2){
int x = Math.min(x1, x2);
int y = Math.min(y1, y2);
int width = Math.abs(x1 - x2);
int height = Math.abs(y1 - y2);
for( int i=0; i < 1; i++){
Ellipse2D.Float elip = new Ellipse2D.Float(x , y,
width/i, height/i);
}
return elip;
}

View Replies View Related

2D Circle Texture Rotation?

Jan 11, 2015

So I have this randomly generated set of tiles that is wrapped in a circle and I'm not really sure how to scroll it around the circle. Basically it's a side-view planet that is in 2D and needs to be wrapped and moving at a controllable rate to give the illusion of planet rotation. What to do to the x and y to make it scroll around. I want every tile except the water tiles to move from left to right and then wrap around the circle. Here's what a planet looks like: [URL] ....

Java Code:

for (int x = 0; x < planet1.length; x++)
{
for (int y = 0; y < planet1[0].length; y++)
{
if (planet1[x][y] == 1 || planet1[x][y] == 2)
{
g.drawImage(water, x * 32, y * 32);

[Code] ....

View Replies View Related

Calculating Area And Circumference Of A Circle

Apr 21, 2014

Here is the code that I wrote out:

//program that calculates the circumference and area of a circle

import java.util.Scanner;
public class circle{
public static void main(String[] args){
Scanner input= new Scanner( System.in);
double r; //declares radius

[Code] .....

And here is what is displayed in the command prompt when I compile my code:

circle.java:17: error: cannot find symbol
r.input.nextdouble();//entered the radius
symbol: method nextdouble()
location: variable input of type Scanner
1 error

What am I doing wrong?

View Replies View Related

Swing/AWT/SWT :: How To Do A Nested Circle Dynamically

Mar 5, 2015

i want to draw a circle inside a circle in java. so far i'm using this piece of code

private Ellipse2D.Float drawEllipse(int x1, int y1, int x2, int y2) {
int x = Math.min(x1, x2);
int y = Math.min(y1, y2);
int width = Math.abs(x1 - x2);
int height = Math.abs(y1 - y2);
return new Ellipse2D.Float(x, y, width, height);
}

View Replies View Related

Calculating Points On A Circle Using Radius

Oct 24, 2014

I have to print points on a circle in increments of -0.1, but when I use a number larger than 1.3, the list stops at 0.1 larger than negRadius, and I don't know why. (Assume the center is (0,0))

public class PointsOnACircleV1
{
public static void main(String[] args)
{
double radius = 1;

[code]...

View Replies View Related

Program To Calculate Area Of Circle

Mar 11, 2015

I'm starting with my version of very basic program: calculating area of circle. And of course it doesn't get well. My question: what is wrong in this code?

public class circleAre{
double radious;
void putData(double radi){
radi = radious;

[Code] .....

View Replies View Related

Make A Circle With Java Coding

Aug 12, 2014

i want to make a circle with java coding.... i tried but i am grtting some error...

View Replies View Related

Shade Portion Of Circle Based On Area Given?

Sep 23, 2014

I am able to draw this image using filloaval() but afterwards when i am calculating some area i have to shade that in the figure in some different color

R is fixed to 100 and d lies between 0 to R

View Replies View Related

Moving Circle - Null Pointer Exception

Apr 9, 2014

I am try to move circle.Below is my code...

import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.image.BufferStrategy;
import javax.swing.JFrame;
import javax.swing.JPanel;

[Code] .....

And I have error

run:
Exception in thread "main" java.lang.NullPointerException
at swingdesing.Game.buffer(Game.java:32)
at swingdesing.Game.moveBall(Game.java:27)
at swingdesing.Game.main(Game.java:51)
BUILD SUCCESSFUL (total time: 9 seconds)

how to overcome this?

View Replies View Related

Write A Class Encapsulating Concept Of A Circle?

Mar 19, 2014

Prompt: Write a class encapsulating the concept of a circle, assuming a circle has the following attributes: a Point representing the center of the circle, and the radius of the circle, and integer.

Include a constructor, the accessors and mutators, and methods toString and equals.
Also include methods returning the perimeter ( 2 x ๐œ‹ x ๐‘Ÿ ) and area ( ๐œ‹ x ๐‘Ÿ^2) of the circle.
Write a client (application) class to test all the methods in your class. I started out trying to thing how to do this and I mapped out a certain idea but do not know how to incorporate the point represent the center of the circle. I am not sure how to proceed further..

import java.awt.*;
public class Circle {
ย public static void main(String[] args) {
ย 
final double PI = 3.14;
int x,y, radius = 4;
double area;
double perimeter;
ย 
[Code] ...

View Replies View Related

LightController And Circle Class - Creating A Constructor

Jan 6, 2015

I have two classes LightController & Circle. I need to use the LightController class to do the following:

Creates an instance of Circle with a diameter of 50 and a colour of OUColour.GREEN and assigns this new circle to the instance variable light.

Sets the xPos of light to 122.
Sets the yPos of light to 162.

I am struggling to write the correct line of code to set the colour to green and set diameter to 50.

Code for the two classes below.

001
import ou.*;
002
import java.util.*;
003
/**
004
* Class LightController
005
* This class uses the Circle class, and the Shapes window

[Code] ......

View Replies View Related

How To Calculate Area Of Triangle / Circle / Rectangle

Mar 3, 2015

package areatest;
import javax.swing.JOptionPane;
public class AreaTest {
ย 
public static double areaTriangle (double length, double width){ //How to calculate the area of a triangle
return .5f * length * width;

[Code] .....

When I try to get the area of a rectangle it gives me 9 no matter what input I give it. When I try to get the area of a triangle it gives me .5 no matter what input I give it. Same with the circle but it always gives me 12.56370...

View Replies View Related

Method Should Return A Double That Is Diameter Of Circle

Jul 9, 2014

What's that diameter? Create a new method for the circle class called diameter. Add this method to the circle class described on page 15-1. It should return a double that is the diameter of the circle. No parameters are passed to this method.

In a tester class, test the performance of your new diameter method as follows:

(Your project should have two classes, Tester and Circle.)

here is what i have so far:

public class Circle
{
public Circle (double r)
{
radius = r;
}
public double area()
{
double a = Math.PI * radius * radius;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Draw A Line (Horizontal) Inside A Circle

Mar 12, 2015

I want to draw a line inside a circle, i what to have a horizontal line. Here is what i have done so far.

import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.Color;
import java.awt.Dimension;

[Code] ....

View Replies View Related







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