Print Isosceles Triangle Depending On Variables Height
Nov 14, 2014
The program needs to print an isosceles triangle depending on variables Height, BorderSymbol and Interior symbol, how to do that. Here is what i did so far :
{
int height = 5;
int i = 0;
int count = 0;
String line = "";
[code]....
and the output is a blanc page nothing on the screen only spaces...
View Replies
ADVERTISEMENT
Dec 10, 2014
I'm taking a class in object oriented programming and we have a task to write a method that returns positive, negative or zero depending on the sum of two variables.
I've had a go at it and i've got to a certain point but i'm struggling to get past this on error - return outside method.
public class Test {
public int sumArgs;
public int arg1;
public int arg2;
[Code] ....
The error occurs on the line 'return "Positive";
View Replies
View Related
Nov 21, 2014
I wrote this code which print a black image depends on the number of rows and columns you give it
public class BlackImg {
private Mycolor[][] colorArr; //Mycolor is a class i wrote that represents colors.
// no need for showing the class here.
// so i created here an array of type Mycolor, for example:
// { {(255,255,255), {(127,127,0)} }
[Code] .....
my problem is that my output comes good except the last line ,
Output:
(0,0,0) (0,0,0) (0,0,0) (0,0,0)
(0,0,0) (0,0,0) (0,0,0) (0,0,0)
(0,0,0) (0,0,0) (0,0,0) (0,0,0)
BlackImg@1db9742 //what is this line , why does it showing up ?
View Replies
View Related
Jun 1, 2014
i want to print triangle shape using number like
this
1
12
123
1234
12345
123456
this is my code
class shape{
public static void main(String [] args){
for(int x =0 ; x<=6;x++){
for(int y =0 ; x > y ; y++){
System.out.print(x);
}
System.out.print("
");
}
}
}
but my output is
1
22
333
4444
55555
666666
View Replies
View Related
Jul 7, 2014
I am trying to make a program that prints triangle... and I did various test on each method to realise that the problem lies with this segment.When I call this method, nothing prints out, I figure there is something with the loop that I am not realizing.the loop is backwards because it's supposed to have the right side edge parralel (when I try to print it out the spaces do not appear, imagine the x are space...), so as each line is looped the # of spaces diminishes
xxxx*
xxx*x*
xx*xx*
x*xxx*
*****
public class test {
public static void main(String[] args){
for (int countdown = 5; countdown <= 1; countdown = countdown--){
showNTimes(countdown, ' ');
showNTimes(5- countdown, '*');
System.out.println("");
}
}
public static void showNTimes ( int nbTimes, char carac ) {
for ( int i = 1 ; i <= nbTimes ; i = i + 1 ) {
System.out.print( carac );
}
}
}
View Replies
View Related
Jun 19, 2014
I am trying to create a program that will estimate a child height based on the height of the parents. It should ask the user to enter a String representing the gender, so m or M for a male and f or F for a female. The program must handle both upper or lower case gender entries. I need it to ask the user for the height of both parents in two parts:
1. for Feet and store in an int variable.
2. for inches and store and int variable.
So for example if the father is 6' 2'', the user would enter 6 when asked for feet and 2 when asked for inches. Convert the height of the each parent to inches. hint 12" in one foot.
Apply the following formulas based on gender (must use an if statement(s)):
Hmale_child = ((Hmother * 13/12) + Hfather)/2
Hfemale_child = ((Hfather * 13/12) + Hmother)/2
I cannot figure out what is missing from my code
<import java.util.Scanner;
public class ChildHeight
{
public static void main(String[] args) {
Scanner scannerObject = new Scanner(System.in);
String gender;
String male;
String female;
[Code] ....
View Replies
View Related
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
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
Feb 15, 2014
So I'm in the middle of creating a model program with voxels. I want to be able to see how the model looks like when I'm in for example my documents (not inside the real program). I want it to show an image of the model, just like a png file shows its image. I've tried looking around, but I've only found threads about changing exe files icon.
Image example:
So, is this possible in Java or do I need to use c/c++ (with JNA) to make this possible?
Or is it not possible at all?
View Replies
View Related
Sep 23, 2014
Write a program that will display a pattern depending on n. Assume n as a one digit odd number.
Example: if n=9, display
*000*000*
0*00*00*0
00*0*0*00
000***000
View Replies
View Related
Jul 24, 2014
I have a jTable with one or 40 rows in it.
The problem is, also when I have only one row in my jTable, the size of the jTable is a little more bigger than 40 rows.
How can I say the jTable, that she should scale to the size of the content?
I don`t want that the jTable is bigger than the content. For example the picture below:
View Replies
View Related
Oct 4, 2014
I know the normal way of naming objects is
Pipe pipe1 = new Pipe
but I want the objects to be made inside a loop and named after how many times the loop have been gone through so I tried
Pipe pipe(numberOfTimes) = new Pipe
where numberOfTimes was a variable counting the loops. This is not working.I need the naming to be pipe1, pipe2, pipe3 etc depending on how many times the loop have been pased
Scanner keyboard = new Scanner (System.in);
String morePipes = ("yes");
int dimRor;
int numberOfPipes = -1;
[code]....
View Replies
View Related
Apr 15, 2014
The program should has the output depending the number I'll input. (The number should be from 1-9) . This is the program's output should be:
Input number: 4
Output:
# # # 1 # # # # #
# # # 2 # # # # #
# # # 3 # # # # #
1 2 3 4 5 6 7 8 9
# # # 5 # # # # #
# # # 6 # # # # #
# # # 7 # # # # #
# # # 8 # # # # #
# # # 9 # # # # #
(Example 2):
Input numbers: 8
Output:
# # # # # # # 1 #
# # # # # # # 2 #
# # # # # # # 3 #
# # # # # # # 4 #
# # # # # # # 5 #
# # # # # # # 6 #
# # # # # # # 7 #
1 2 3 4 5 6 7 8 9
# # # # # # # 9 #
(Example 3):
Input number: 5
Output:
# # # # 1 # # # #
# # # # 2 # # # #
# # # # 3 # # # #
# # # # 4 # # # #
1 2 3 4 5 6 7 8 9
# # # # 6 # # # #
# # # # 7 # # # #
# # # # 8 # # # #
# # # # 9 # # # #
I'm not asking the code to make this program, I have trouble to understand the algorithm to make this program ...
View Replies
View Related
Oct 5, 2010
I am stuck trying to build a relatively "simple" GUI. The GUI should have one JComboBox that allows the user to pick from one of three locations. Then based on their choice, another JComboBox should be generated with another set of choices. The key is that the second ComboBox should have different choices depending on the selection made in the first one. So, in theory, the logic should be something like:
//create new JComboBox array of strings "locations"
//create new JComboBox array of strings "costToTravelThere"
//if user picks location 1 from the first ComboBox
then add the second ComboBox with options specific to that first location
else if user picks location 2 from first ComboBox
then add the second ComboBox with options specific to that second locatoin
I understand how to do the basic stuff, like create the JFrame and the actual panels and ComboBoxes, etc. What I don't understand is how to implement the second ComboBox dependent on the first one. I'm not very experience with Listeners and such, and I'm sure that's a big part of this.
View Replies
View Related
Jun 24, 2014
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
public class Racquet {
private static final int WIDTH = 60;
private static final int HEIGHT = 20;
[code]....
The problem arises at the portion of the code that says
private int Y = game.getHeight() - 70;
I am not actually getting any compiler errors, but when I try to run the program, the command prompt pops up with this message:
Exception in thread "main" java.lang.NullPointerException
at Racquet.<init>(Racquet.java:19)
at Game.<init>(Game.java:10)
at Game.main(game.java:58)
What I want to do is make it so a GUI object that I created moves with the screen when I change the height. If I change it to private int Y = 330; the program works just fine.
View Replies
View Related
Nov 12, 2014
So I'm trying to make a bar graph, each bar will increment the height by about 10 pixels. To do this, I'm making an array of bars. For some reason, using fillrect I cannot not increase the size more than 10 by 10, if I do, it will only show the 10 by 10. I want the bars to increase in height by 10 each time.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class AssortedAssortmentsOfSorts extends JFrame
[Code] .....
View Replies
View Related
Jun 2, 2015
Compute the height of a stack. Then determine whether that value is found in the stack element .
View Replies
View Related
Sep 26, 2014
I developed a swing application using group layout. It resizes when I resize the frame but when I change the screen resolution or when I run the application in a laptop which has small sized screen, the components over lap each other. I need my application to fit according to the screen resolution
The code is as follows
private void initComponents() {
jComboBox1 = new javax.swing.JComboBox();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
[Code]...
According to the list item selected, an internal frame will appear in the desktop pane. I use group layout for that internal frame too.
View Replies
View Related
Mar 14, 2015
I am creating a login form for my project and it works great,the issue is that i want to open up different forms dependent on the username and password that i enter.for example if i enter a password 'manager' then it should open the manager page,or 'employee' should open the employee page.
I'm thinking that it is just a case of creating another sql query but i have tried and i cannot see the solution,i can open the employee page by default but that is not what i am trying to achieve. I am using an sqlite database which holds the username and password.
Here is my code
private void btn_LoginActionPerformed(java.awt.event.ActionEvent evt) {
// code to login to the back office system
String sql =" select username,password from Employee where username =? AND password =?";//sql query
try{
pst =conn.prepareStatement(sql);
[Code] ......
View Replies
View Related
Jul 30, 2014
This is a part of my program. When the user enters "Exam Schedule" in the JtextField and clicks the add button I want the link to change to a link that opens a local pdf file. And if the user enters "Academic Calendar" the Jlabel will be set to another link. So far this works fine but the problem is that if you erase the textfield and enter another value the link of the previous value will still be there.
public void actionPerformed (ActionEvent e){
if (e.getSource ==add) {
if (text.getText().equalsIgnoreCase("Exam Schedule")){
link1.setText(text.getText());
link1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
[Code] ....
View Replies
View Related
Nov 13, 2014
So for an assignment I have to write a method that finds that height of this BST. I wrote this:
public int height(Node node)
{
if (node == null)
{
return 0;
}
else
{
return 1 +
Math.max(height(node.left),
height(node.right));
}
}
Which makes sense in my head. However, I added a couple of nodes in and realized I'm not sure how to call this method.
public static void main(String[] args) {
Tree<String, String> tree = new Tree<String, String>();
tree.add("A", "1");//some added stuff
tree.add("B", "2");
tree.add("C", "3");
tree.add("D", "4");
tree.add("E", "5");
tree.add("F", "6");
tree.add("G", "7");
tree.add("H", "8");
System.out.println(tree);
System.out.println(tree.height());
What exactly do I put in the parenthesis after tree.height? If you need to see more of my code I can do that but it is quite lengthy.
View Replies
View Related
May 5, 2014
Normally, the height of the CENTER component (or position) is greater than that of the NORTH and SOUTH components in a BorderLayout.
Is it possible to increase the size of the SOUTH component and decrease the size of the CENTER position because the jcomponents I want to add in the SOUTH component are bigger? or shall I have to change the layout and use some other layout?
View Replies
View Related
Jun 22, 2014
Why isn't heig ever equal to heightShipArray[count] no matter what letter I type in
String[] heightShipArray = {"A", "a", "B", "b", "C", "c", "D", "d", "E",
"e", "F", "f", "G", "g", "H", "h", "I", "i", "J", "j"};
boolean trueHeight = true; // checks if height is a letter between a-j/A-J
do {
Terminal.printLine("Input height with letters A to J");
[Code] ...
View Replies
View Related
Jul 9, 2014
I have a requirement where in the content of the text area is dynamically populated from the database. I am able to successfully retrieve and display the data on the text area.
However when the content is too large, I am not able to dynamically set the height of the text area. When I try to display the same as a label, the display is flawless, dynamically sets the height as per the content. So, I tried to create a label, with same content and dynamically bind the height to the preferred height as below, but it doesn't work.
// Generate User Note Description
TextArea textArea = new TextArea();
Label text = new Label();
// SETTING THE TEXT TO A LABEL TO RETRIEVE THE HEIGHT
text.setText(usrNotes.getNote().trim());
[Code] ....
View Replies
View Related
Jan 20, 2015
I want to use to tableview one beside the other so that they appear as a single table. but I do not find how to bound the height rows of the two tableview.
View Replies
View Related
Jul 30, 2014
This is a part of my program. When the user enters "Exam Schedule" in the JtextField and clicks the add button I want the link to change to a link that opens a local pdf file. And if the user enters "Academic Calendar" the Jlabel will be set to another link. So far this works fine but the problem is that if you erase the textfield and enter another value the link of the previous value will still be there.
public void actionPerformed (ActionEvent e){
if (e.getSource ==add) {
if (text.getText().equalsIgnoreCase("Exam Schedule")){
link1.setText(text.getText());
link1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
[Code] .....
View Replies
View Related