Print Upper Half Of Hourglass

Aug 26, 2014

I am only able to print upper half of the hourglass.

public static void printHourglass(int size, char symbol) {
int count = 0;
int count2 = 0;
boolean lower = false;
for(int lines = 0; lines < size; lines++)
{
//upper half

[code]....

View Replies


ADVERTISEMENT

Flip Bottom Half And Copy It To Produce Upper Half Of Shape

Jun 15, 2014

So my goal is to use the graphics class to draw this shape: [URL] ....

so far I've managed to draw the bottom half, but now I want to utilize the copyArea() method to flip the bottom half and copy it to produce the upper half of the shape: [URL] ....

and this is what I wrote to produce the bottom half:

import java.awt.Graphics;
/*
* 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.
*/

public class MyFrame extends javax.swing.JFrame {

/**
* Creates new form MyFrame
*/
public MyFrame() {
initComponents();

[Code] .....

View Replies View Related

Stars Program - How To Make Hourglass

Apr 30, 2015

I just recently started programming and came across the star patterns which normally I am able to do extremely quickly except with this one. I am trying to make a hourglass but I seem to only be able to make the top of it. How to do the opposite so I can finish the hourglass.

package hourglass;
class Hourglass {
public static void main (String[] arguments){
for(int j=1;j<=5;j++) {
for(int i=1;i<=j;i++)

[Code] .....

View Replies View Related

Letters Of A String That Occur From Second Half Of Alphabet

Feb 11, 2014

Write a method named secondHalfLetters that accepts a string as its parameter and returns an integer representing how many of letters in the string come from the second half of the alphabet (that is, have values of 'n' through 'z' inclusive). Compare case-insensitively, such that uppercase values of 'N' through 'Z' also count. For example, the call secondHalfLetters("ruminates") should return 5 because the 'r', 'u', 'n', 't', and 's' come from the second half of the alphabet. You may assume that every character in the string is a letter.

View Replies View Related

Return Height Of Heap Of Sand In Bottom Of Hourglass

Nov 18, 2014

I am working on program and have been struggling to get around step 5 and 6 given below.

I have got on with the first couple of points. Where to begin with steps 5 and 6.

Java Code:

class Hourglass {
int height;
int bottomHalf;
public Hourglass (int h) {
height =h;
}
public Hourglass (){
height=3;
}

/*Write a method dropGrain that simulates one grain of sand falling into the bottom half of the Hourglass. If all the sand is already at the bottom before a grain is dropped, this method should cause the hourglass to be flipped, meaning that all the sand will be in the top again. Then, one grain of sand should fall. */

//Hint: this method can be quite short. All you need to do is update one attribute.

public void dropGrain(){
}

/*Write a method getHeapHeight() which returns the height of the heap of sand in the bottom of the hourglass.

Hint: a triangle of height h contains h*h grains (=1+3+5+...+h).

So determining the height when the amount of sand in the bottom half is a square (1,4,9,16,...) is easy. Think about what happens if the amount of sand is not exactly a square.*/

public int getHeapHeight() {
} mh_sh_highlight_all('java');

View Replies View Related

Switch Not Recognizing Upper Case Q

Mar 30, 2014

why this switch code does not work for the 'Q'. Everything works fine for the other cases, i.e. 1,2,3, and 'q', but when I type in 'Q', I get the default case. Please note all the values have been defined in an earlier part of the code but for simplicity's sake I have removed them below

do { 
switch (choix) {
//demande le nombre de patons a achete
case '1':

[Code].....

View Replies View Related

Program Exits Even When Click No Or X Button On Upper Corner

Mar 31, 2015

Here is the snippet of code that is causing the problem

Java Code:

addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent e)
{
int confirm = JOptionPane.showOptionDialog(
VendorMachineSimulation.this,
"Are You Sure you want to close this application?",
"Exit Confirmation", JOptionPane.YES_NO_OPTION,

[Code] ....

My question is why does the snippet code at the top works in the class processAction but when I add to the main class that extends JFrame, it exits regardless if I click yes, no or the x button.

View Replies View Related

Check For Upper Case Letters From User Input - Cannot Find Symbol Compile Error

Apr 15, 2015

I decided to code this quiz I took in class about asking the user to input a string and the code is suppose to check for upper case letters. If a upper case letter is found, it should increase a count by one. Once the check is done, it should display the number of uppercase letters. For some reason I am getting this weird compile error stating that symbols can't be found...

Java Code:

import java.util.*;
import java.lang.*;
public class StringCheck{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("please enter a string: " );
String s = input.nextLine();

[Code] ......

View Replies View Related

Checking If Matrix Is Upper Or Lower Triangular Matrix Based On User Input

Dec 5, 2014

java program that will determine if the matrix is a lower or upper triangular matrix. I only need to use java.util.Scanner;.

View Replies View Related

How To Make Print Employee Button To Print Info Of Other Class

Apr 12, 2014

Basically the class is supposed to have a static variable that keeps track of the number of companies (numberOfCompanies) that have been created and a static method that returns the value of this variable. I need to have a constructor and a method to addEmployee, a method to printCompany, and a toString method. The addEmployee method will check that there is only 1 salesperson, 2 designers, and 4 manufacturing persons at a time and will check that there are no more than 7 employees of the company.

The addEmployee method will return a String indicating what the error is (i.e. "There is already a sales person in this company") or a null if the employee was added. If attempting to name a third company, an error message will be shown. what i have so far but my print company mmethod returns null company class :in which i am obliged to use inputdialog because it says that it cannot return void when i use the showmeassage diaolog.

company class:

import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Company {
private ArrayList<Employees> list ;
private static int numberOfCompanies;

[Code] ....

error message when print button is clicked:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
at javax.swing.JOptionPane.createInternalFrame(Unknown Source)
at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)

[Code] ......

View Replies View Related

Two Threads - One Will Print Odd And Other Will Print Even Numbers In Sequence

Jul 25, 2014

I want to create two thread one thread will print odd number and another thread will print even number. but the number should be in a sequence like

1 2 3 4 5 6 7 8 9 10

View Replies View Related

How To Print First 5 Values

Nov 16, 2014

See the below:

public static void main() {
int i; // counter
  createDeck(); // this is a function call
  // Show the cards in the deck
System.out.println("The deck is as follows:");
for (i=0 ; i < CARDS_IN_DECK ; i++)

[code]....

It is now printing out the value of myDeck[5] but I need to print out first 5 values.

View Replies View Related

Unable To Print Sum Of First Row?

Dec 11, 2014

Java Code:

public class Lab12 {
public static int SumRow(int [][] a){
int row, column, sum=0;
for (row=0;row<2;row++ ) {
sum=0;
for (column=0;column<2;column++) {
sum=sum+a[row][column];

[Code]...

my output is

The sum of row 1 is: 3
The sum of coloumn 0 is: 5
The sum of coloumn 1 is: 5
The max of row 0 is: 4
The max of row 1 is: 2

it is supposed to print the sum of row o first ?

View Replies View Related

How To Print Before And After A Word

Nov 28, 2014

i have completed a code in java so that it can read spaces in a line but when i run it if i put Line 1 test test for example it will print : [ 3] spaces in Line1 test test what i want to print is [ 3] spaces in "Line1 test test" so the diferences is at " Is there any possible thing that i can do?

class Main
{
public static void main( String args[] )
{
System.out.print( "#Enter text : " );
String text = BIO.getString();
while ( ! text.equals( "END" ) )
{

[Code]...

View Replies View Related

Can't Print Number

Oct 14, 2014

I can't print the number that is supposed to come out

public class Skateboard {
private int wheels = 4;
private int trucks = 2;
private int bearings = 8;
private int gripTape = 1;
 
[code]....

How come sb1.assembly() doesn't return the values? :/

View Replies View Related

JSP :: How To Print Alphabets

Feb 24, 2014

I am trying to print alphabets from A to F using <c:forEach>

<c:set var="ctr" value="${optListSize}"></c:set> //optListSize is the size of an arraylist
<c:forEach begin="65" end="${ctr}" varStatus="loop" step="1">
<c:out value="<%=String.fromCharCode(64+${ctr})%>"></c:out>
</c:forEach>

I tried the above code but it gives an error. How to go about printing A, B, C, D... incrementally

View Replies View Related

How To Print Out First 6 Character Of Last Name

Feb 20, 2015

How to i print out the first 6 character of a last name even if the last name is and X like Malcolm X or Sung Li. X and Li being the last names

View Replies View Related

How To Print Big Integer Using For Loop

Mar 6, 2015

I amtrying to iterate a value of L,R both are range of BigInteger but its not working

BigInteger L=in.nextBigInteger();
BigInteger R=in.nextBigInteger();
for (BigInteger bi =L;
bi<=bi.compareTo(R);
bi = bi.add(BigInteger.ONE)) {

//Task to do with Numbers
}

I am trying to iterate a for loop in range of L and R but its not working

View Replies View Related

Print A Diamond Using For-loop?

Mar 26, 2014

I am currently trying to print a Diamond using for-loops but I seem to be confusing my self / over-complicating it.

This is what I have so far [URL]). When I run the code I get [URL].

I want to duplicate it on to the other side but I can't seem to be able to figure out a working for-loop to print it out.

Also, is there a faster/efficient method of doing something like this?

View Replies View Related

How To Print A Different Statement In If Else Structure

Feb 6, 2015

Implement a Las Vegas slot machine! The machine works as follows. First, it generates three random integers (use import java.lang.Math.*; then call Math.random()*7 to generate a random number between [a,b)) that are in the range of 0-7. Once the numbers are generated, the following rules are used to determine the prize:

- If all three numbers are equal to 7, you are winning $1,000,
- If all three numbers are equal, but not equal to 7, you are winning $500,
- If two of the numbers are equal to 7 and the third one is six, you are winning $400,
- If two numbers are equal, you are winning $100,
- Otherwise you are not winning anything.

And for that I wrote:

import java.lang.Math;

public class Assn1_2150130 {
public static void main(String[] args) {
// Generate three random signle-digit integar from 0-7.
int n1 = (int)(Math.random()*7);
int n2 = (int)(Math.random()*7);
int n3 = (int)(Math.random()*7);

[code]...

But I just can't figure out a way to print out the "YOU WON NOTHING." independently.If I say that n1!=n2 && n2!=n3 && n3!=n1, and then write another line of println. It gives out the number as well as the "NOTHING".

View Replies View Related

JSP :: How To Print Null Values In EL

Dec 18, 2014

The value is: ${object1.property1} If the value of the property is null, I want "null" to be printed, like this:

The value is: null But I get an empty string, like: The value is:

I know I can use a ternary operator, but isn't there a simpler/shorter solution? A function (like NVL() in SQL)?

The value is: ${empty object1.property1 ? "null" : object1.property1 }

Not only is this long, but the value expression is typed twice, which is a magnet for bugs.

View Replies View Related

While Loop To Print All Odd Numbers Between 1 And 100

Apr 3, 2015

I want to write a while loop to print all odd numbers between 1 and 100.

But it gives error. Where is the mistake?
 
public class pro {
public static void main(String[] args) {
// TODO Auto-generated method stub 
int c;
int x=1;
 
[Code] ....

View Replies View Related

How To Print String Only Five Times

Feb 11, 2015

I can't figure out how to print this string only five times. I tried to use the * operator, but that doesn't work with strings apparently, unles i'm not importing correctly.
 
import java.lang.String;
public class Looparray
{
public static void main(String args[] {
for (String myStr= "Hello there!";;) {
System.out.print (myStr);
System.out.print("
");
}
}
}

View Replies View Related

Print Text To File

Apr 29, 2014

I'm not getting text in the Pledge.txt file. Do I need to assign the pledge to a String variable?

Java Code:

import java.io.*;
import java.util.*;
public class ReadMe {
public static void main(String[] args) throws IOException{
File file = new File("Pledge.txt");
PrintWriter output = new PrintWriter(file);

[Code] .....

View Replies View Related

Symbol Won't Print From For Loop

Oct 20, 2014

On line 45 i am trying to add "-" symbol to my output phone number. As of now the out prints like "1800*45*3569377. I want it to print 1800-3569377, or even more ideal: 1-800-356-9377. When printing normally (system.out.println) I can print symbols, but when I try to print from a for-loop it says "unclosed character literal." import java.util.Scanner;

public class Phone_010473030 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a phone number string: ");
String Phone_num = input.nextLine();
Phone_num = Phone_num.toUpperCase();

[code]....

View Replies View Related

How To Print JFrame With All Its Subcomponents

Oct 5, 2014

I have a form in netbeans java. I want to print the form as it is.Actually I want to print the bill. I am beginner in netbeans java.

View Replies View Related







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