Create A Pattern Of Stars

Jul 2, 2014

So I'm studying for a test i have coming up on recursion so i was playing around with it. I ended up making a pattern of stars that look that such :

*
**
***

The code i had for that was

public void makePattern(int size){
if(size == 0){
System.out.println();
}
else if(size > 0){
System.out.print("*");
makePattern(size - 1);
}
}

I was wondering if i wanted to expand on this and make it do something like

*
**
***
**
*

What condition would i have to add i was struggling trying to figure it out...

View Replies


ADVERTISEMENT

How To Create A Custom Layout Pattern

Feb 19, 2015

I would like to implement a custom Logging strategy for my Java project.I have implemented 3 appenders : one console-log, one file-log (errors only) and another (custom) file-log (with the custom parameters).The custom parameters are : loggerName, logPathDir, logFileLevel and layoutPattern.

I have not managed yet to implement a custom layoutPattern strategy for the custom file-log.When I launch my tests : test1 (default logging setting) and test2 (custom logging setting), I have only managed to get a sucessfull status if I switch the custom layoutPattern strategy to the default one for the test2. My implementation extract :

// Layout patterns : default (layout) and custom (patternLayoutCustomBuilt)
Layout<String> layout = PatternLayout.createLayout(PatternLayout.SIMPLE_CO NVERSION_PATTERN, config, null, null, false,
false, null, null)
PatternLayout.Builder patternLayoutCustom = PatternLayout.newBuilder();
PatternLayout patternLayoutCustomBuilt = patternLayoutCustom.withPattern(layoutPattern).wit hConfiguration(config).build();

[code]....

View Replies View Related

Create A Checkerboard Pattern With 2 Nested For Loops?

Feb 12, 2015

Im trying to create a checkerboard pattern with 2 nested for loops . I need to output asterisk characters. Im supposed o use an n int so I dont know if im limited to that 1 int. Im only getting 1 line of asterisk.

* * * * *
* * * * *
* * * * *
* * * * *
package checkerboard;
public class Checkerboard {
public static void main(String[] args) {
for (int row = 1; row < 6; row++){
System.out.print("* ");
for (int col = 6; col < col; col++) {

[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

Recursive Method And Printing Out Stars?

Nov 23, 2014

KtMok1t.jpg

Below is what I go so far, but how to do star C and E.

public class PrintTriangle
{
public static void printStars (int star)
{
for (int number = 0; number < star;number ++)
{
System.out.print("*");

[Code] ....

View Replies View Related

Model Galaxy - Multiple Stars With Different Masses

Mar 12, 2014

Here is a link to the program: [URL] ....

I am trying to model a galaxy so that I have multiple stars certain distances away from each other and with different masses.

The accretion and than cylinder expansion happens with just about every galaxy.

I have a few questions.

First My computer only runs this if the number of particles is in the 500s. If that's the case How can I increase the probability that I will when I get to it have a red giant?

Second how can I modify this so that I have a timescale during which white dwarfs form from some stars and you see in the single stars either no supernova or nova just degeneration or a type 2 supernova and in binaries a type 1a supernova which is like a type 2 supernova of 1 star when it is a red giant, that giant becoming a white dwarf, the other star becoming a red giant, and then the white dwarf sucking gas from the giant until it explodes and ejects its companion?

Third how can I make this compacted and taking up less space in case I want to expand it to a few galaxies or even start with a big bang?

Basically what I am asking is how can I make this like a universe?

View Replies View Related

Draw V-shape Of Height N Entered By User With Stars

Apr 12, 2014

Am stuck in a problem that asks to write a program using nested for loops to draw a V-shape of height "n" entered by the user with stars .

View Replies View Related

Adding Stars After Each Item In The List - For Loop Isn't Working?

Feb 26, 2014

This is supposed to be a method that adds stars after each item in the list.

Java Code:

import java.util.ArrayList;
public class ClientProgram {
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<String>();
list.add("the");

[Code] ...

I'm guessing it's because list.size() changes, though but it should only find that value in the beginning, so it shouldn't be a problem?

View Replies View Related

Update Sequence Of Stars According To Actual English Word And Guess Character

Jan 12, 2014

Below is part Two the method I need creating:

This method updates the sequence of stars according to the actual English word and the guess character.

public static String updateSecretWord(String secretWord, String englishWord, String guessedChar)
{
}

Below is the example of how it should look like when I call it

updateSecretWord(“*****”, “Hello”, “h”) = h****
updateSecretWord(“h****”, “Hello”, “o”) = h***o
updateSecretWord(“he**o”, “Hello”, “e”) = he**o

View Replies View Related

Exam Results - Code Should Split Results In Stars In 4 Categories

Nov 30, 2014

I'm doing a program where a user enters in exam results for students. Once he's entered the code, the code should split the results in stars in 4 categories.

I am working with a while loop that prints out infinite results. What I want to do is, if the user enters 2 digits, say "12", it should output 1 "*".

If the user enters "21" and "22", it should output "**".

There are 4 categories of marks which are marked with ints range1, range2, range3 and range4, which are user enter digits. Part 1 of the code is to split the user entered digits into its correct ranges. the ranges are 0-29, 30-39, 40-69 and 70-100. I've done the part where when the user enters a digit, it goes into the correct variable. After that when the user enters a digit over 100, the enter results should show up as stars. For example

Enter number =

21
22
44
66
44
23
11
111 (the 111 is where the program breaks and moves on)

So it should then display

0-29 ****

30-39

40-69 ***

70-100

Whatever I'm trying, it displays an infinite amount of stars. If I try to use break, It only outputs a single star, no matter how many digits I enter

Here is the code

int mark = 0;
int range1 = 0, range2 = 0, range3 = 0, range4 = 0;
int count1 = 0, count2 = 0, count3 = 0, count4 = 0;
while (mark >=0 && mark <=100) {

[Code] .....

"The problem is with the while loop, the one above is something I was experimenting with "

View Replies View Related

How To Add Spaces To A Pattern

Apr 21, 2015

I have created this program that outputs

1
12
123
1234
12345
123456

I tried looking up some ways to create spaces in between each number, but I failed miserably. Here is what I have right now.

public class Iterations {
public static void main(String[] args){
for(int i=1;i<=6;i++)
{
for(int j=1;j<=i;j++)
System.out.print(j);

[Code] ....

View Replies View Related

Printing Pattern When Name Is Given

Mar 10, 2014

I want to know how to print this type of pattern when a name is given ???

Example:

name given TEJA

Capture.PNG

View Replies View Related

How To Apply Format Pattern

Jan 12, 2015

I am able to get Cpu speed using my GetProcessorSpeed method and It returns this output 1796. How can apply this pattern "#.##". I am trying something like this.

Format formatter=new DecimalFormat("#.##");
formatter.format(MainClass.GetProcessorSpeed());
label2.setText(formatter.toString());

View Replies View Related

Head First Design Pattern

Jan 11, 2014

I was reading head first java and the author told to read head first design pattern next.

View Replies View Related

String Pattern Match

Apr 24, 2015

Why the following string fails the test below:

@Pattern(regexp = "^[_a-zA-Z0-9-]+(.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(.[a-zA-Z0-9-]+)*.(([0-9]{1,3})|" +
"([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$", message = "Not a well-formed email address")

View Replies View Related

Pattern Matches In Java

Jul 3, 2014

I have code which validate code enter by user

the requirement say the maxlength=2 and minlength=1 and is a string

the user can enter code as follows

00
A1
HH
12
10
09

I have this Java Code:

public boolean isValidPattern(String s_value, String s_pattern) {
boolean flag = false;
if (Pattern.matches(s_pattern, s_value)) {
flag = true;
}
return flag;

[Code] ....

My problem is when user put

A1 AM geting error

View Replies View Related

Inheritance For Word Pattern

Apr 24, 2014

I am in an intro programming class and we got assigned a problem for creating a super class with about a dozen sub classes for generating a random word(via WordGetter class) and then comparing that word to a variety of different patterns(like: does the word contain "re"). We were given the super class which looks like this...

public class Pattern {
public boolean matches(String text) {
return true;
}
public String toString() {
return "(TRUE)";

[code]...

and from this class, we have to write subclasses that override those three methods. I am struggling to understand inheritance and I am not really sure where to even start. Here is the instructions for the first sub class we need to write...

"CONTAINS" SUBCLASS
Constructor: The constructor accepts a String named ‘letters’.

Matches: This pattern matches any text that contains at least one occurrence of each ‘letter’.
toString: produces the text “(CONTAINS <LETTERS>)” where <LETTERS> is the ‘letters’ string.
getLetters(): this method must return letters.
equals(Object): careful on this one. Two Contains are equal if they have the same letters (order is not relevant).
(Example):

Pattern p = new Contains(“re”);
boolean f1 = p.matches(“renew”); // f1 is true
boolean f2 = p.matches(“zoo”); // f2 is false
String s = p.toString(); // s is “(CONTAINS re)”
boolean f3 = p.equals(new Contains(“er”)); // f3 is true.. really..

View Replies View Related

Triangle Pattern (For Loop)

Feb 21, 2015

I'm trying to make a triangle which should look like this. But I cant seem o figure it out.

1
2 1
4 2 1
8 4 2 1
16 8 4 2 1
32 16 8 4 2 1
64 32 16 8 4 2 1
128 64 32 16 8 4 2 1

This is the code I have written so far.

public class TestProgram
{
public static void main(String[]args)
{
for (int columns=0; columns<=8; columns++)
{
for (int rows=columns; rows>=1; rows --)
{
System.out.print(rows+ " ");
}
System.out.println();
}
}
}

View Replies View Related

Composition Pattern In Java

Jun 27, 2014

I'm having a hard time implementing a simple composition example in Java:

Java Code:

public class CompositionPattern {
public static void main(String[] args) {
Udp udp = new Udp();
Imap imap = new Imap();
udp.startService();
imap.startService();

[Code] ....

The above won't compile. It says "The method supportsMe() is undefined for the type Object". I understand that I stored parent as an Object. But in reality it is not simply Object, but a Udp object or Imap object. The point is to make Responder generic. I don't want to have to cast the Object to Udp or Imap. Any solutions so I can keep this generic?

View Replies View Related

Singleton Pattern In Java

Apr 21, 2003

I have heard about using patterns in core java.Is it possible?If yes, how?

View Replies View Related

Design Pattern Selection

Mar 27, 2015

I need selecting which design pattern to use in my case.

I am creating a list of objects "items" to be presented in a list for the user to choose from, all objects have a title and a check box. Some objects have additional textbox for user input, some objects have additional image for illustration, and some objects have additional textbox and image as well.

I read and saw online videos but not sure if my selection "Factory Design Pattern" is the best match.

View Replies View Related

Observer Controller Pattern (MVC)

Dec 10, 2014

Model View Controller design pattern I completely understand then I was told about the observer controller pattern. After reading and reading I and watching video clips on youtube explaining it I have a question:

Isn't the actionListener the observer so to speak. It is firing whatever action it is told to do and dynamically updates the program to.

Example, I have a JButtons and a JTextArea. I press the button and it gives the current stock price of some stock, I press it again it refreshes. Sounds like an observer to me... Am i on the right track here?

View Replies View Related

Printing Pattern Using Recursion

Jul 16, 2014

The program I'm working on is supposed to read input from a file and using recursion, print the pattern of asterisks for each value until the value is either < 0 or > 25.For example, if the value was 4, the pattern would look like this

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

The values are stored in a file entitled prog3.dat which looks like this

4
3
15
26
0

I've never used recursion before and haven't been able to find anything showing how it would work with this particular type of problem.Here is what I've been able to come up with so far, but I'm having problems still which I will show following the code.

import java.util.Scanner;
import java.io.*;
public class Program3 {
public static void main(String[] args) throws Exception {
int num = 0;
java.io.File file = new java.io.File("../instr/prog3.dat");
Scanner fin = new Scanner(file);

[code]...

It appears to be reading the file correctly, but is only printing the top half of the pattern. Also, like I said, I'm not very familiar with recursion, so am not sure if this is actually recursion?

View Replies View Related

Recursion Pattern In Java

Jul 16, 2014

The program I'm working on is supposed to read input from a file and using recursion, print the pattern of asterisks for each value until the value is either < 0 or > 25. For example, if the value was 4, the pattern would look like this
 
*
* *
* * *
* * * *
* * *
* *
*
 
The values are stored in a file entitled prog3.dat which looks like this
 
4
3
15
26
0
 
I've never used recursion before and haven't been able to find anything showing how it would work with this particular type of problem. Here is what I've been able to come up with so far, but I'm having problems still which I will show following the code.
 
import java.util.Scanner; 
import java.io.*;
public class Program3 {
public static void main(String[] args) throws Exception {
int num = 0;
java.io.File file = new java.io.File("../instr/prog3.dat");
Scanner fin = new Scanner(file);

[Code] ....
 
Output:
 
Please enter an integer
*
* *
* * *
* * * *
Please enter an integer
*
* *
* * *
Please enter an integer
 
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
Please enter an integer
Please enter an integer
 
As you can see, I don't know how to make it print the pattern like in the example and am honestly not even sure if this is recursion since I've never actually worked with recursion before.

View Replies View Related

How To Use Regular Expression Using Pattern

Mar 16, 2015

I have a string "We have 7 tutorials for Java, 2 tutorials for Javascript and 1 tutorial for Oracle" I need to replace the numbers based on the below condition.
 
if more then 5, replace with many
if less then 5, replace with a few
if it is 1, replace with "only one"
 
below is my code, I am missing the equating part to replace the numbers

private static String REGEX="(d+)";
  private static String INPUT="We have 7 tutorials for Java, 2 tutorials for Javascript and 1 tutorial for Oracle";
  //String pattern= "(.*)(d+)(.*)";
  private static String REPLACE = "replace with many";
  public static void main(String[] args) {
  // Create a Pattern object

[Code]...

View Replies View Related

Pattern Matches In Java

Jul 3, 2014

I have code which validate code enter by user. The requirement say the maxlength=2 and minlength=1 and is a string, the user can enter code as follows :

00
A1
HH
12
10
09
 
I have this code

public boolean isValidPattern(String s_value, String s_pattern)  {
        boolean flag = false;
        if (Pattern.matches(s_pattern, s_value)) {
            flag = true;
       
[Code] .....

my problem is when i put

A1 is still giving error

View Replies View Related







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