Generate Output Pattern Depending On N
Sep 23, 2014Write 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
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
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 ...
package com;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.*;
@WebServlet(urlPatterns = "/alan", name = "NullS", asyncSupported = true)
public class Null extends HttpServlet {
[Code] ....
When I run this servlet this generates thousand of lines of output. Whats the problem?
I am trying to write a program that will generate a QR Code from an input text and also display some information about the input/output bits. So far I have created the frame and what to do next. And I'm not sure if I am on the right track since my level of programming is not that great. By the way, I am using zxing libraries from GitHub. I know, there are plenty of generators online for the QR Code, but that is not what I am looking for. As you can see on the attached image, I am more interested in the efficiency of encoding 2D data. Also, I noticed that almost all the online projects regarding 2D codes are for Android. Which is not very useful.
// QR Code Generator
package qrcode;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
[Code]....
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?
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]....
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.
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";
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.
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...
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] ......
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] ....
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] .....
I need creating a code that will create random addition or subtraction from 0-500 depending on their grade level. I know how to create a random for the math and subtraction. I just dont know how to get it to change depending on their grade level. Example I need it to ask their name, grade level, addition or subtraction then five addition or subtraction questions depending on what they chose.
View Replies View RelatedI'm trying to get the program to roll a four sided die between 100 and 1000 times, depending on your input, and then displaying the answer.
public class Lab08
{
public static void main(String[] args)
{
int v1 =0, v2 = 0, v3 = 0, v4 = 0;
int n;
char response;
System.out.print("Enter number of rolls (100-1000): ");
[Code] ....
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 ?
I am trying to use parallel arrays to store names and job titles, then display the name/job title combo depending on which is entered. I have always struggled with arrays, so I'm sure that's where my issue is, but I am not sure how to resolve this one. I tried to use the toString() method with the jobs to see if that would allow the job title to match to one of the titles listed, and I tried to not use the toString() method with the names to see if that would allow the name entered to match to one of the names listed in the array. Both options only display the "invalid" message no matter what I enter. What would be the best choice to use the arrays to properly display the information ....
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JEmployeeTitle2 extends JApplet implements ActionListener
{
Container con = getContentPane();
[Code] .....
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] ....
I want to know how to print this type of pattern when a name is given ???
Example:
name given TEJA
Capture.PNG
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());
I was reading head first java and the author told to read head first design pattern next.
View Replies View RelatedWhy 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")
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
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...
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..
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();
}
}
}