ArrayList Output Display Without Brackets?

Feb 9, 2015

I'm trying to get my output to be displayed without the brackets.The output looks like this

22 ([1, 2, 11])
33 ([1, 3, 11])
44 ([1, 2, 4, 11, 22])
55 ([1, 5, 11])
66 ([1, 2, 3, 6, 11, 22, 33])
77 ([1, 7, 11])

But I want it to have no brackets displayed so it looks like this

22 (1, 2, 11)
33 (1, 3, 11)
44 (1, 2, 4, 11, 22)
55 (1, 5, 11)
66 (1, 2, 3, 6, 11, 22, 33)
77 (1, 7, 11)

import java.util.ArrayList;
public class Palindrome {
public static void main(String[] args) {
int e = 0;
// palindromic composite number
int drome = 0;

[Code] ....

View Replies


ADVERTISEMENT

Display Some Messages On Output File In Display Head Function

Mar 18, 2014

Write a class named FileDisplay with the following methods:

1.) constructor: the class's constructor should take the name of a fil as an arugment.
2.) displayHead: This method should display only the first five lines of the file's contents

Here is the following code I have made so far

import java.io.*;
public class FileDisplay
{
private String filename;
 public FileDisplay(String Filename) throws IOException

[Code] ....

First, in my constructor I have taken in an argument and used that argument to open up an output file. Meanwhile, I'm trying to work n the displayhead method to print out information and to read data to. I haven't opened up my input file yet, but I'm not understand how can I read a print data to an output file. in

public void displayHead()
{FileWriter file=new FileWriter(Filename)}

do I make create another instance of the filewriter class to output data?

In simple words, suppose to I want to display some messages on my output file in the displayhead function. Since I already have opened up the file in the constructor, how do I combine that in this method...

View Replies View Related

Need Output To Display Whole Number

Dec 2, 2014

I need the output to display like this:

At Billy Goat's Restaurant, the price of our good tasting Hotdog is $1.50.

But it is output display is like this:

At Billy Goat's Restaurant, the price of our good tasting Hotdogis 1.5

In the second array i use a double, is that not correct?

import java.util.Scanner;
 public class FinalProject
{
public static void main(String[] args)
{
String[] FoodDescription = {"Hotdog", "Fries", "Hamburger", "Pepsi", "IceCream"};
double [] cost = {1.50,.80,2.25,1.00,.75};

[Code] ....

View Replies View Related

Display Name Of All People In ArrayList Containing Passed In Keyword

Dec 8, 2014

i need to write a method, that passes in an arraylist and a keyword,and display the name of all the people in the arrayList whose name contain the keyword (irrespective of uppercase or lowercase). how to write such a method ??

View Replies View Related

JSF :: How To Convert Hashmap Values To Arraylist To Display On Page

Apr 2, 2015

I need assigning the selected hashmap values into a list and to display the values in a jsf page. The user will select certificates and will be stored in the below list:

private List<String> selectedCertificates = new ArrayList<String>();

The selectedCertificates will have the values ("AA","BB"). Now I will be passing the list into a hashmap in order to get the names and to display them on the jsf page.

My code is below:

Map<String, String> CertificatesNames =
new HashMap<String,String>(selectedCertificates.size());
CertificatesNames.put("AA", "Certificate A");
CertificatesNames.put("BB", "Certificate B");
CertificatesNames.put("CC", "Certificate C");
for(String key1: selectedCertificates) {
System.out.println(CertificatesNames.get(key1));
}

I want to display in my jsf page :

Certificate A
Certificate B

Now my issue is that is how to display all the values of the CertificatesNames.get(key1) in the jsf page as I tried to do the below and it printed all the values when I used the #{mybean.beans} using the :

List beans =
new ArrayList(CertificatesNames.values());

So how to do this?

View Replies View Related

Display User Input In Lower Case - Why No Output In Second TextField

Jun 2, 2014

I've done a lot of hardwork for this assignment but I don't know what's why the second textfield which is for output is blank.

All I want is to get the input from user in textfield a and display it in textfield b in lower case.

public void KeyPressed (KeyEvent ke) {
String letter2="";
if(ke.getKeyCode()==KeyEvent.VK_A)
{
letter2=letter2+"a";
btextfield.setText(letter2);

[Code] .....

View Replies View Related

Display Contents Of File In Reverse Order - Output To Console

Jun 24, 2014

Create a class that allows the user to select a file and output the contents of the file to the console. Recommend using a text file to display, java files are text files. You may want to put this code in a method to allow you to complete the remainder of this assignment without overwriting your code.

- You should ask the user to enter the full path to your file to make certain you are processing the correct file.

- Modify your code/add a method to display the contents of the file in reverse order. You do not need to reverse the characters on each line but simply output the lines of the file in reverse order.

Hint: read the content of the file into an ArrayList and then traverse the ArrayList.

this is what i go so far.

package classActivity;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Select
{
public static String enterFilePath()

[Code] ....

View Replies View Related

Display And Resize Multiple Rectangles Independently - Using Objects From ArrayList

Jan 13, 2014

I have a code to resize a single rectangle. I would like to display and resize multiple rectangles independently and according to my research on the net, the best way is to use an arraylist. So I modified the code in this sense, except ...when I run the code, the rectangles appear good but impossible to resize. I think the problem comes from mousePressed, Released, Dragged and Moved methods. When I use the mouse to resize the rectangle, nothing happens. The code does not interact with the arraylist, and therefore with rectangles it "contains". Resizing is my main class, the MouseAdapter is in the Resizer class (below).

Resizing component;      boolean dragging = false;      // Give user some leeway for selections.     
final int PROX_DIST = 3;      Path2D.Double selectedPath;        public Resizer(Resizing rz) {         
component = rz;          component.addMouseListener(this);         
component.addMouseMotionListener(this);     

[Code] .....

View Replies View Related

Evaluating Expression Without Brackets

Feb 3, 2015

I am working on a program to evaluate an expression without brackets using stacks. I am getting the following error :

3+1*2+4
-2.0

Exception in thread "main" java.util.EmptyStackException
at java.util.Stack.peek(Stack.java:102)
at java.util.Stack.pop(Stack.java:84)
at assignment2.Evaluate.main(Evaluate.java:42)

I imported the Stack from java.util.Stack

package assignment2;
import java.util.Scanner;
import java.util.Stack;
public class Evaluate {
public static void main(String[] args) {
Stack<String> ops = new Stack<String>();

[Code] ....

What is causing this error? Does it look like the program should function as intended?

View Replies View Related

Curly Brackets Placed Incorrectly

Oct 22, 2014

At this moment in time my program compiles and runs as I want it to, but when I look at my code I see that my While Loops braces are placed inside my Try Block. When I move these braces outside of the Try Block, next to the WhileLoop, the program doesn't run like I want it to.

Likewise, when I place the While(answerIsCorrect) inside the Try Block, it doesn't work like I want it to either.

Also, my problem is on Lines 17 and 18.

import javax.swing.*;
import java.util.Random;
public class SwingInputExample
{
public static void main(String args[])
{
int firstNumber=0;
int secondNumber=0;
int correctAnswer=0;
String studentGuess = null;

[Code] ....

View Replies View Related

Create A Program That Will Calculate Different Tax Brackets

Oct 3, 2014

I have spent the past 12 hours on it and have gotten no where. I need to create a program that will calculate different tax brackets. I have tried all combinations I can think of and can't get it to work!!! I am literally about to go insane! I need the program to calculate tax will be 1% for anything up to $50000. If the tax is over $50000, you keep that 1% of $50000 and then add the remaining. So for an income in the second range, it would be 1% of $50000, and then 2% of (income - $50000). This then continues for each range.

The problem I'm having is getting it to display the correct interest rates. I am not asking for you to write it for me. I want to learn. But at this point I have exhausted all resources available to me.

import java.util.Scanner;
public class Project3taxinfo {
public static void main(String[] args) {
final double RATE1 = 0.01; //1% tax on the first $50,000
final double RATE2 = 0.02; //2% tax on the amount over $50,000 up to $75,000
final double RATE3 = 0.03; //3% tax on the amount over $75,000 up to $100,000
final double RATE4 = 0.04; //4% tax on the amount over $100,000 up to $250,000
final double RATE5 = 0.05; //5% tax on the amount over $250,000 up to $500,000
final double RATE6 = 0.06; //6% tax on the amount over $500,000

[code]....

View Replies View Related

Removing Brackets From Array List Printout

Apr 10, 2009

When you "system.out.print(arraylist)" an arraylist, it will give you something like [item1, item2].

Im wondering how I can remove the "[" and "]" brackets fromt he printout, or even if i pass it in as another variable.

View Replies View Related

Inserting Else Statement And Multiple Brackets At Various Places

Jan 16, 2014

I'm using this try statement to check for errors in input in my Tic Tac Toe game. The problem I have having is I don't understand why this error is happening. It's preventing my code from compiling. I've tried inserting an else statement and multiple brackets at various places with no success.

Java Code:
public void play(){
Scanner input = new Scanner(System.in);
int row, col;
char currPlayer = 'X';

[code]....

View Replies View Related

Balanced Brackets Execution - Keep Getting Empty Stack Exception

Oct 21, 2014

Im trying to do this program but I keep getting Empty Stack Exception when I execute balancedBrackets. I know that push and pop methods works, but I'm not so sure if my logic for balancedBrackets is correct.

public void push(T t){
if(this.top+1==this.size){
duplicateCapacity();
}
else{
top++;
arr[top]=t;

[Code] .....

View Replies View Related

Generate QR Code From Input Text And Display Information About Input / Output Bits

Nov 12, 2014

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

View Replies View Related

Create Own ArrayList Using Collection Without Implementing ArrayList Itself

Feb 28, 2014

I'm trying to create my own arraylist using Collection. My program doesn't do anything. Obviously, I haven't a clue.

import java.util.Collection;
import java.util.Iterator;
public class MyArrayList<T> implements java.util.Collection<T> {
private int size = 4;
private T[] mArray;
public MyArrayList(String[] args) {

[Code] ....

View Replies View Related

Output For If Else Is Missing Second Output

Feb 15, 2015

my output fails to display me the 2nd output.Here's my code.

import java.util.Scanner;
public class year
{
public static void main (String [] args)
{
Scanner console = new Scanner (System.in);
System.out.print("Enter the choice of book(A-ABC,D-EFG):");
String x = console.next();
System.out.print("Enter the rate (1-3):");
int y= console.nextInt();
System.out.print("Enter number of kids reading:");
int k = console.nextInt();
 
[code]....

When I key '0" for kids, it did not appear the second print out. I don't want the first print out to be the output.

View Replies View Related

JSP :: Display XML - Catch Is To Display Each Tag With Different Colors

Nov 19, 2014

I am developing a product where the client needs to display the content of XML in a JSP page. This XML will be extracted from database and will be temporarily sotred in a String object and will then be flushed to JSP page for display. This was working fine unitl now. But now the customer wants display each tag with one color. attribute in another color and data in another color.

For ex: <?xml version="1.0" encoding="UTF-8"?>

this should be displayed in one color. Then

<ichicsrmessageheader>Data</ichicsrmessageheader>

In the above one the tag should be displayed in one color and "Data" should be displayed in another color

<organisation operationtype="1">Data</organisation>

In the above sample tag should be in one color and attribute should be in one color ex: red and value of the attribute should be in another color ex: blue and "Data" should be in one color ex: green.

Here is the sample screen shot of how xml should is currently being displayed.

View Replies View Related

Populating ArrayList Object With Nested ArrayList Object

Jul 8, 2014

I have stumbled onto a problem with ArrayLists (not sure if nested ArrayList objects would be a more accurate description) ....

As simply put as I can describe it, I have an Inventory class which creates an ArrayList of a Product superclass, which has two subclasses, PerishableProduct and ItemisedProduct.

By default, the program is meant to have a starting inventory, which is why I have added them in the constructor

public class Inventory {
private List<Product> products;
public Inventory() {
addProduct(new Product("Frying pan", 15, 20));
addProduct(new PerishableProduct("Apple", 5.8, 30, 7));
addProduct(new ItemisedProduct("Cereal", 5.8, 0));
// this is where I am having problems. Wanting to add
// objects to the ItemisedProduct's ArrayList for cereal.
}

Within the ItemisedProduct subclass is yet another ArrayList which is meant to hold serial numbers.

public class ItemisedProduct extends Product {
private ArrayList<String> serialNumbers = new ArrayList();
public ItemisedProduct(String name, double price, int qty) {
super(name, price, qty)

[Code] .....

My problem is that I do not know how to populate the serialNumbers ArrayList from the Inventory class' constructor. Because technically, quantity is defined by how many serial numbers are created.

View Replies View Related

Output Of A Staircase?

Jan 9, 2014

New to programming, see my code

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

[Code]....

the staircase looks good,however I want to remove the last line and if user chooses 9 i want them to get message "enter number from 1 to 8" and do not print out the staircase.

View Replies View Related

Transferring Output To GUI?

Apr 2, 2014

I have been working through a problem, and I have working what I need to work. However, it prints out to the command line and I want to output to a GUI. I have set up the GUI and everything seems fine there, the problem is when I try to change the output that was coming through the command prompt to a JTextField. I am getting the following error.

The field DataAnalyzerGUI.dataOutput is not visible

Java Code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DataAnalyzerGUI extends JFrame {
private JPanel contentPanel;
private JButton btnExit;
private JButton btnClose;
private JButton btnFBdata;

[code]....

View Replies View Related

How To Reverse Output

Aug 30, 2014

I need this to print output opposite the way it is. When it reads my file it prints it out like this:

4X^0+3X^1+-2X^2+5X^3+6X^5

But is needs to be this:
6x^5+5x^3+-2x^2+3x^1+4x^0

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Iterator;
import java.util.Set;

[code]....

View Replies View Related

Output In Columns

Mar 1, 2014

Any way i can format this output into columns?

for(int i = 0; i < 5; i++) {
System.out.println(t[i]+n[i]+s[i]);
}

View Replies View Related

Why Is Output Not Being Displayed

Jan 14, 2015

I am writing this program for my Java level 1 class. I am able to get it to compile and run, however nothing is outputted. Below are the instructions and the code that I have written.

Instructions:

Write an application that calculates and displays the amount of money a user would have if his or her money could be invested at 5 percent interest for one year. Create a method that prompts the user for the starting value of the investment and returns it to the calling program. Call a separate method to do the calculation, and return the result to be displayed.

Below is the code that I have written

import java.util.Scanner;
public class Interest
{
//main method
public static void main(String[] args)
{
originalAmount();
Scanner input = new Scanner(System.in);
 
[code]....

View Replies View Related

If Then For ArrayList?

Feb 26, 2015

I think it's a problem with my if then else statements but I'm not sure?

package Hw1;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; 
 public class ScrapWork {
public static void main(String[] args){
String[]Dalton={"Joe","William","Jack","Averell"};
 
[Code] .....
 
run:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - illegal start of type
at Hw1.ScrapWork.main(ScrapWork.java:16)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

View Replies View Related

Max And Min In ArrayList

Nov 14, 2014

I have an ArrayList with String, String, Double.

From another class I would like to print minimum and maximum including the first String name.

I have tried with import java.util.Collections; but that didn't work.

Java Code:

ArrayList<List>list = new ArrayList<List>();
list.add(new List("Abc","Cba",1));
list.add(new List("Bca","Bca",5));
list.add(new List("Cba","AcB",2)); mh_sh_highlight_all('java');

I would like the result to look like:

Minimum: Abc 1
Maximum: Bca 5

View Replies View Related







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