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


ADVERTISEMENT

Floyd Triangle - Accept Line Number From User And Print Only That Particular Line

Sep 10, 2014

Write a program that accepts the line number from the user and prints only that particular line from the Floyd triangle.

Example:
Input: 2
Output: 2 3

Input: 3
Output: 4 5 6

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

Area And Perimeter Of Triangle - Decimal Formatting Error?

Sep 28, 2014

I am also having trouble with another program.

Java Code:

import javax.swing.JOptionPane;
import java.util.*;
import java.text.DecimalFormat;
import java.util.StringTokenizer;
public class ShelbyHarms_3_03 {
public static void main (String [] args) {
double a, b, c; //Input sides of triangle
double x; //Perimeter of triangle
double area; //Area of triangle

[Code] .....

Here are the errors:

ShelbyHarms_3_03.java:39: error: variable x might not have been initialized
JOptionPane.showMessageDialog(null, formatter.format(x));
^
ShelbyHarms_3_03.java:42: error: variable area might not have been initialized
JOptionPane.showMessageDialog(null, formatter.format(area));
^
2 errors

Am I not formatting the decimal format right?

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

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 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

Display Error - Cannot Find Symbol

Oct 31, 2014

This is my Error:

MergeList.java:55: cannot find symbol
symbol : variable Arrays
location: class MergeList
System.out.println(Arrays.toString(merge));
^

This is my code:

public static void main(String[] args) {
int[] first = { 1, 4, 9, 16 };
int[] second = { 9, 7, 4, 9, 11 };
int[] merge = new int[first.length + second.length];
int j = 0, k = 0, l = 0;
int max = Math.max(first.length, second.length);

[Code] ....

View Replies View Related

Calculate Total Amount Paid And Display It - NULL Error

Dec 10, 2014

Exception in thread "main" java.lang.NullPointerException
at ShoeStore.calculateTotal(ShoeStore.java:103)
at ShoeStore.main(ShoeStore.java:88)

This is the error when program is ran. The program is supposed to calculate the total amount paid for all shoes and display it.

import java.util.Scanner;
 public class ShoeStore
{
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String shoe_Name, nameStore, type;
int size, shoeAmount;
double sellingCost;
 
 [Code] .....

View Replies View Related

Program That Display GPA With Message

Mar 21, 2015

As a part-time student, you took two courses last term. Write a Java program that calculates and displays your grade point average (GPA) for the term. Your program should prompt the user to enter the grade and credit hours for each course. This information should then be displayed with the lowest grade first, and the GPA for the term should be calculated and displayed. A warning message should be printed if the GPA is less 2.0 and a congratulatory message if the GPA is 3.5 or above.

View Replies View Related

Inventory Program - Display Information To GUI

Feb 28, 2015

I am trying to create a GUI with already existing code. My assignment is: Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the GUI should display the value of the entire inventory, the additional attribute, and the restocking fee.

Where to start. The text book does not cover a GUI that displays this type of information rather it just displays graphics. I would like to create a separate class that holds the GUI information just to make everything flow better. I have provided my current code below:

Java Code:

// ProductTest.java
// by JakeB
public class ProductTest {
// main method begins
public static void main(String[] args) // begin main {
myGUI display = new myGUI();
display.setVisible(true);

[Code] .....

This is all I have for the GUI. I am at a total loss and I am behind 2 weeks now. I cannot move forward until I am able to get this done and the class ends next week.

View Replies View Related

Program That Will Have GUI Window And Display Image?

Jun 24, 2014

I am writing a program that will have a GUI window and displays an image when clicked on the image changes and clicked on again the image changes once more. Here is what i have.

package ButtonLab;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

[Code]....

The issue i am having is when i run it the window pops up but with no images. The images wont load, I have tried to use the c: path to the image also.

View Replies View Related

Why Program Does Not Display Anything When Choices Are Inputted

Feb 28, 2014

I am experimenting with messages in JOptionPane and I was wondering why this program does not display anything when the choices are inputted.

*note: I tried putting "JOptionPane.showMessageDialog(null, "This is an information message", "Information", JOptionPane.INFORMATION_MESSAGE);" after the "int i = 0;" and then the messages displayed.

Scanner scan = new Scanner(System.in);
int i = 0;
while (i != 6)
{
System.out.println("1. Information message");
System.out.println("2. Error message");
System.out.println("3. Question message");
System.out.println("4. Plain message");
System.out.println("5. Warning message");

[code]....

View Replies View Related

Create A Program That Display Video In Second Monitor

Mar 12, 2014

create a program that display video in second monitor ....every time i run my code it display the video in first monitor not in second monitor .. Here my path i used

private static String mplayerOptions = "mplayer -noborder -vo fbdev2 -nokeepaspect movies.mpeg";

View Replies View Related

Recursion Program - Display Sum Function To User

May 1, 2014

This is a simple recursion program I had to write. I just cant seem to display my sum function to the user

import java.util.*;
import java.io.*;
public class Recursion {
public static void main(String[] args) {
int number = 0;

[Code] .....

View Replies View Related

Write A Program That Display Miles And Kilo

Apr 21, 2014

1. Write a program that displays the following table (note that 1 mile is 1.609 kilometer):

Miles Kilometers
1 1.609
2 3.218
3 4.827
...
...
9 14.481
10 16.090

Note: use for loop and printf() to format your output

public class MilesandKilometers {
public static void main(String[] args) {
System.out.println("Miles Kilometers");
int miles = 1
;
for (int i = 1; i <= 10; miles++, i++) {
System.out.println(miles + " " + miles * 1.609);
}
}
}

how to make it like the instruction said " use for loop and printf() to format your output".

View Replies View Related

Java Program - Display Up To 5 Pairings Of Data Types

Sep 7, 2014

I need to write a simple program that displays up to 5 pairings of data types (int, string) (string, long) ect. I need to have at least two classes, a Pair class (generic) and an PairTest class.

View Replies View Related

Program To Initialize And Display Variable Size Array

Aug 18, 2014

Write a program to initialize and display variable size array.

View Replies View Related

Write A Program That Read Integer And Display Diamond

Oct 14, 2014

Write a program that reads an integer and displays, using asterisks, a filled diamond of the given side length. For example, if the side length is 4 the program should display.

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

I have it where it displays the top half of the diamond. But i cannot figure out how to get it to draw the bottom half.

import java.util.*;
public class E616 {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
System.out.print("Enter number of rows. ");
int N=input.nextInt();

[code]...

View Replies View Related

GUI Program - Enter File Name And Display Text Area

Apr 14, 2014

I have to write a gui program where I can enter a file name and then it gets displayed in a text area when I click Open. Conceptually, I do not get this. I was thinking of appending the text file into a string or something, but I guess I'm confused on how it all works and how I can open the text file. Not asking for the code, but just a compass or something.

View Replies View Related

Program To Display Both Largest And Smallest Of A Series Of 5 Integers

Apr 27, 2014

Here is a simple program on applets that is giving me a bit of headache since it cannot always display the two numbers that it is supposed to: the largest and smallest of the five input integers.....I cannot see where i went wrong, you can always create separately the HTML file to load the applet in an appletviewer of your won size.

*
23.6 (Largest and Smallest) Write an applet that reads five integers, determines which are the largest and smallest integers in the group and prints them. Draw the results on the applet.
*/
import java.awt.Graphics;
import javax.swing.JApplet;
import javax.swing.JOptionPane;

[Code] .....

View Replies View Related

Java Program Which Would Display A Message Dialog Box Stopped Working

Mar 16, 2014

I have a java program which would display a message dialog box. The problem is it would stopped working before even displaying the message dialog box. This is my code.

import javax.swing.JOptionPane;
public class HelloDialog {
public static void main(String [] args) {
JOptionPane.showMessageDialog(null, "Hello World!");
}
}

There is a pop-up window which would say "Java(TM) Platform SE binary has stopped working." I am using textpad. What should I do with this?

View Replies View Related

Program That Read Sequence Of Input Values And Display Bar Chart

Oct 21, 2014

Write a program that reads a sequence of input values and displays a bar chart of the values, using asterisks, like this:

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

You may assume that all values are positive. First figure out the maximum value. That value's bar should be drawn with 40 asterisks. Shorter bars should use proportionally fewer asterisks.

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

[Code] ....

The problem is that all this code does is print 1 line of *'s and what seems to be thousands of them

View Replies View Related

Ask User To Enter Number From 1 To 10 And Program Will Display Roman Numeral

Feb 6, 2014

I am trying to write a program that asks the user to enter a number from 1 through 10 and then the program will display the roman numeral for that number.

I am also adding a error message in which i haven't yet because im still trying to figure out how to the program will do the roman numeral.'

I have used the if and else if. but when i input a number it just repeats the number back to me.

The program cimpiles but it doesn't do what i want. here is what i have so far. how can i get the program to display the roman numeral after the number is entered.

import javax.swing.JOptionPane;
public class Romannumeral
{
public static void main(String[] args)
{
double number;
 
[Code] .....

View Replies View Related







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