Why Program Not Printing Square And Triangle

Nov 21, 2014

import java.util.Scanner;
public class justin10a

public static void main(String [] args)
{
int n;
n = getSize();
 
[Code] .....

View Replies


ADVERTISEMENT

Find Area Of Triangle / Square / Rectangle Or Trapezoid

May 19, 2014

I started with finding the area of a triangle, but now I'm trying to ask a user what kind of shape they want the area for, then ask questions to get the area. I can't figure out how to take the shape a person types to go to a certain case. It also says shape hasn't been initialized. I don't know how to do that.

import java.util.Scanner;
public class TriangleArea {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args){
char shape;
String text = "Do you want to find the area of a triangle, square, rectangle, or trapezoid?";
System.out.print("Text");
switch(shape){

[code]....

View Replies View Related

Create Little Program Which Enter Number / Program Says Triangle Exist Or Not

Mar 16, 2014

i want create little program which enter the number, ant program says triangle exist or not. So code :

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

[code]...

So when i put first num like 1, next num like 2 and next num like 100 , program says Triangle exist.

View Replies View Related

Creating Cursor For A Game That Moves Square By Square - Removing Trailing Images

Aug 31, 2014

I'm trying to create a cursor for a game that moves square by square. While it will move to the next square, though, it leaves the image of the previous cursor on the last square it was on.

As a visual explanation, this is what the program looks like on launch:

This is what it's suppose to look like after you press the right arrow key once (made by forcibly changing launch coordinates):

And this is what it actually looks like after you press the right arrow key once:

Here is the code for the program:

package cursortest;
import javax.swing.*;
import java.awt.*;
import javax.imageio.*;
import java.io.*;
import java.awt.event.*;
public class CursorTest extends JPanel implements KeyListener{

[Code] ......

I'm fully aware that I could just use g.clearRect on the area and remove it for sure, but I know for a fact I shouldn't have to as I have another program I made a long time ago that tried to do something similar without needing to resort to that.

View Replies View Related

How To Get Main Triangle Program To Run

Oct 17, 2014

I am having trouble getting my main triangle program to run. My teacher gave us a sample program, so I tried running his, and it doesn't run either.

Here is the class:
 
import java.util.Scanner;
 public class ShelbyHarms_3_06_Triangle {
private double sideA, sideB, sideC; // Instance variables, numbers for area and perimeter
static Scanner console = new Scanner(System.in); // Establish keyboard
 
[Code] .....

My errors for the main program(the class has no errors) are:

helbyHarms_3_06.java:37: error: cannot find symbol
theSides.getSides();
^
symbol: variable theSides
location: class ShelbyHarms_3_06

[Code] ....

5 errors

View Replies View Related

Returns Area Of Triangle / Unless Triangle Not Value So Return String?

Dec 28, 2014

I'm doing a problem where the area of a triangle is returned (if valid). However, I want to return a message (i.e. 'triangle is not valid) if the triangle is invalid.

I'm not sure how to go about to doing this as my method (called area) will only let me return doubles. Possible to return a string in an else within my area method?

public class MyTriangle {
public static void main(String[] args) {
//triangle is valid if the sum of any two sides is bigger than the third
System.out.println(isValid(3, 4, 5));
System.out.println(area(543, 4, 5));

[Code] ...

View Replies View Related

Area Of Triangle Java Program?

Sep 2, 2014

I've been having trouble with this code for about a week and I've finally got it down to one error. Here is the code:

import java.util.Scanner;
public class Triangle {
public static void main (String[] args) {
Scanner Console = new Scanner(System.in);
System.out.print("Please enter the three lengths of your Triangle: ");
double a = console.nextDouble();

[Code] ....

And here is the error:

Triangle.java:30: error: class, interface, or enum expected
} // End class
^
1 error

View Replies View Related

Creating Program For Area And Perimeter Of Triangle

Sep 1, 2014

import java.lang.Math;
public class triangle {
double area; double s;
public double findArea(double sideA, double sideB, double sideC);
{
s= 0.5 *(sideA + sideB + sideC);
area = Math.sqrt(s*(s-sideA)*(s-sideB)*(s-sideC));

[Code] ...

Errors I am getting:

Triangle.java:23: error: class, interface, or enum expected
import java.util.Scanner
^
Triangle.java:25: error: class, interface, or enum expected
public static void main(String[] args) {

[Code] ....

View Replies View Related

Error In Program To Display Floyd Triangle

Aug 9, 2014

I want to display triangle with for or if loop in java prog as:

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
.
.
.
79. . . . . . . . . .91

here is code and error file

eror of for: E:Javajdkbin>javac tri.java tri.java:16: error: reached end of file while parsing } ^ 1 error code of above error:

Java Code:

class tri
{
public static void main (String args[]) {
int i,j,a=0; for(i=1;i<=79;i++) {
for(j=1;j<=i;j++) {
a++;
System.out.print(" ");
System.out.print(a);
}
System.out.print("
");
}
} mh_sh_highlight_all('java');

View Replies View Related

How To Compare Square Of The Square Root Of Any Number

Feb 20, 2014

How would I compare the square of the square root of any number. The difference in these values is due to the rounding error in Java.

Example: Enter number 2

The answer I should get is: 2.000000000000004
Round off error: -4.440892

View Replies View Related

Program That Shows A Square Frame Filled With 100 Buttons Label

Apr 13, 2014

Write a program that shows a square frame filled with 100 buttons labeled 1 to 100. Nothing needs to happen when you press any of the buttons. I keep getting errors i am a beginner.

import java.awt.Frame;
import javax.swing.JButton;
import javax.swing.JPanel;
class TestFrame extends Frame {

[Code] ...

View Replies View Related

Magic Square Program - File Not Found Exception Error

Apr 25, 2014

I am working on a magic square program. My program compiles. However, when I enter the square dimension it does not select the correct file. The error says "java.io.FileNotFoundException." It looks like it inserts 0 instead of the entered dimension.

import java.util.*;
import java.io.*;
public class Trial2
{
public static int size, row, col;
public static void main(String[]args)throws java.io.IOException

[Code] ....

View Replies View Related

Algebra - Perfect Square Java Program / Find Smaller Integer N

Sep 22, 2014

Write a program that prompts the user to enter an integer m and find the smallest integer n such that m * n is a perfect square. (Hint: Store all smallest factors of m into an array list. n is the product of the factors that appear an odd number of times in the array list. For example, consider m = 90, store the factors 2, 3, 3, 5 in an array list. 2 and 5 appear an odd number of time in the array list. So, n is 10.)

so far my program is just like this.

import java.lang.Math;
import java.util.Scanner;
public class PerfectSquare {
public static void main(String[] args) {
Scanner m = new Scanner(System.in);
int Fint;

[Code] .....

how do i make the program find the smallest integer n?

View Replies View Related

Array Program Printing Error

Apr 25, 2014

Ok, so the program we are supposed to do is to create implement a employee class then create a main tester class that can accept user inputs for 5 employee names, salaries, and performance rating. After that, we have to input code to calculate a provided raise amount, then print out the array with the updated raises. I have completed the program with no syntax errors, but it doesn't do anything. not even a screen comes up on my end to accept user inputs. I know its something basic, but what am i missing

Employee class
public class Employee
{
private String employeeName;
private int salary;
private int performanceRating;

[Code] ....

View Replies View Related

Printing Amortization Table For Program

Jul 15, 2014

I am still having trouble with printing an amortization table for my program. This is the example the professor gave us and our program has to print exactly like this:

Please enter the amount of the loan (a number less than $1,000,000.00) 1000.00
Please enter the annual interest rate (between 2.0 and 15.0 inclusive) 10
Please enter the term of the loan (a number of years between 1 and 30 inclusive) 1
Your monthly payment is 87.92
| INTEREST | PRINCIPAL
MONTH 1 : 8.33 79.58
MONTH 2 : 7.67 80.25

[code]....

So far I have it so it works up to the table. How to get it to loop so it will print each month with the principal and interest. This is the part im having trouble with:

double principal = amount;
double principalPaid;
double interest;
double totalInterest;
double balance = amount;

[code]....

View Replies View Related

Creating TXT File - Program Keeps Printing Exception Error

Apr 10, 2014

I'm trying to have the program create a .txt file for me but it is not working properly. It just keeps printing the exception error "The file could not be found" and exits the program.

// This program asks the user for input for a name, phone number and notes up to 200 entries.
// It stores every contact in a file. Type 'h' for help while running this program.

import java.util.Scanner;
import java.io.*;
public class Phonebook {
static Entry[] entryList = new Entry[200];
static int numEntries;
public static void main(String[] args) {

[Code] ....

After running the code, I go into my workspace folder and I see that the file was created. What to do because running the program will always print "could not find the file".

View Replies View Related

Magic Square Says No

Nov 25, 2014

I'm having a small issue with my output on my code. here is what my output is: The magic value for your square is 34, which means that every row, column and diagonal of your square must add up to that number.

Please enter the 4 values for row 0, separated by spaces: 1 2 15 16
Please enter the 4 values for row 1, separated by spaces: 13 14 3 4
Please enter the 4 values for row 2, separated by spaces: 12 7 10 5
Please enter the 4 values for row 3, separated by spaces: 8 11 6 9
Checking square for problems:
DIAG: VALID
ROWS: VALID
COLS: VALID
RANG: VALID
MAGIC: No

MAGIC should be YES. However i keep getting it saying no.This is the correct output..The magic value for your square is 34, which means that every row, column and diagonal of your square must add up to that number.

Please enter the 4 values for row 0, separated by spaces: 1 2 15 16
Please enter the 4 values for row 1, separated by spaces: 13 14 3 4
Please enter the 4 values for row 2, separated by spaces: 12 7 10 5
Please enter the 4 values for row 3, separated by spaces: 8 11 6 9

Checking square for problems:
DIAG: VALID
ROWS: VALID
COLS: VALID
RANG: VALID
MAGIC: YES

Here is my code..

import java.util.Scanner;
public class pdonahue_Magic {
public static void main(String args[]) {
int[][] theSquare = new int[4][4];
Scanner s = new Scanner(System.in);
System.out.println.

("The magic value for your square is 34, which means that every row, column and diagonal of your square must add up to that number.");

System.out.print("Please enter the 4 values for row 0, separated by spaces: ");
theSquare[0][0] = s.nextInt();
theSquare[1][0] = s.nextInt();
theSquare[2][0] = s.nextInt();
theSquare[3][0] = s.nextInt();

[code]....

View Replies View Related

How To Make Square Which Is Filled With (dot)

Oct 17, 2014

Do I want to make something like this:

*****
*.....*
*.....*
*.....*
*****

I am stuck, I have made a code that creates this and don't know how to complete it.

*****
* *
* *
* *
*****

Code:

class Main {
public static void main( String args[] ) {
System.out.print("#Enter number of stars :");
int stars = BIO.getInt();

[Code] ....

View Replies View Related

How To Find If BigInteger Is Square

Jul 3, 2014

I have a program i m not sure how to implement :

(Square numbers) Find the first ten square numbers that are greater than Long.MAX_VALUE . A square number is a number in the form of n 2 . For example, 4, 9, and 16 are square numbers. Find an efficient approach to run your program fast.

I found two ways of solving this but i think both are way inefficient :

-A square number can be divided in lesser square numbers :

what's the square of 36 ? 36 is 2 * 3 * 2 * 3 => 4 * 9 => square is 2 * 3

-second option is to estimate a number and increase it or decrease it based on how close that number * number is to the BigInteger starting number , as as it gets closer the delta gets smaller until it gets to 1

View Replies View Related

Nth Square Root Of Any Number

May 14, 2009

This is a mathematical problem. I got one of the equations I need to compute down to

n^(1/6)

Or the 6th root of n.

Now the Java code I have for this is as follows, since Java has no nth root function I'm raising it to a power of a 1/6.

System.out.println(Math.pow(64.0, 1/6));

Now, the only thing it will print is 1.0

However the 6th root of 64 is 2!!!!

View Replies View Related

Create Square Matrix That Has Min And Max Value

May 10, 2015

I have to create a square matrix that has a min and max value as well as a size value which is given a integer value in the main method. The matrix has to be filled with random values. Also I have to add that matrix to another one in an addMatrix method and I have to subtract both in a subMatrix method. These are the requirements:

Methods:
Constructor() - receives the row and col size for myMatrix and a max and min values for range of random fill values for the matrix.
RandFill() - fills matrices with random numbers
addMatrix() - receives a matrix object. adds its myMatrix with the received object's myMatrix. The result is placed in this object's myResultMatrix.
subMatrix() - subtracts both matrices

I typed up this code but I'm not sure about some parts of it and I would creating min and max values in the Random method and in the main printing the separate 2 matrices and adding and subtracting them:

import java.util.*;
public class SquareMatrix2 {
public int size;
public int myMatrix [][];
public int myResultMatrix;
public int [][] ResultStatus;

[Code] ....

View Replies View Related

Timer - Why Does Square Not Moving

Sep 7, 2014

Why does my program write that i have problem in Timer?

public class Ball extends JPanel implements ActionListener {
Timer timer = new Timer (3, this);
int x = 0, y = 0, aX = 2, aY = 2;
public void PaintComponent(Graphics g){
Graphics2D g2 = (Graphics2D) g;

[Code] ....

View Replies View Related

Creating Solid Square

May 3, 2014

I aim to create a solid square using this:

public class asteriskSquare {
public static void main(String[] args) {
for (int x = 1; x <= 4; x++){
for (int y = 1; y <= 4; y++){
System.out.println("+");
}
System.out.println("+");
}
}
}

All I'm getting is a single column of "+".

View Replies View Related

How To Build Triangle Using Loops

Jan 16, 2014

I need to build the triangle like below. How to solve this using loops.

*
* *
* * *
* * * *
* * * * *

View Replies View Related

Properties Of A Triangle - X And Y Coordinates

Oct 29, 2014

A triangle is defined by the x- and y- coordinates of its three corner points. Compute the following the following properties of a given triangle: the lengths of all sides, the angles at all corners, the perimeter and the area. The program must prompt a user for the point coordinates. I have created a class Triangle and a class TriangleSimulator, I am stuck and can't figure out why my program won't run correctly.

import java.util.Scanner;
public class Triangle {
Scanner in = new Scanner(System.in);
private int x1;
private int x2;
private int x3;

[Code] ....

View Replies View Related

Programming About Finding Triangle

Nov 25, 2014

class triangle
{
public static void main (String[] args)
{
System.out.println("Provide three side lengths - 000 to terminate.");
int a = In.getInt();
int b = In.getInt();
int c = In.getInt();
 
[code]....

My problem is that when I enter 5,2,5 it should be isosceles and acute but it comes out as isosceles and obtuse, and when I type 5,5,5 it comes out equilateral and right. The only one that works is if I enter 3,5,4 it will come out as scalene and right. I been at this for a while and my math looks correct.

View Replies View Related







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