Printing Out String Out Of Index?

Jan 24, 2014

I am writing a Java permutation program, it takes in N and k and gives k amount of combinations based on N length.

That portion works, but the portion I have that does not work is when k is greater then 1, the array is then then printing strings out of index.

The perm algorithm ends on index - 1 for moving characters but then I push all those characters into an Array List, I would think I could print them off however I want from there but that is not the case. I'll include the minimum amount of code possible.

//permString = 1234 or something, it doesn't matter
//Use Case N = 4 k = 3, prints out 123,124,132,134 ect
//Use Case N = 4 k = 2, error index out of range but only on the printing function; the perm function doesn't take k and
//is based on length
//the "" is just an empty string
permNow("", permString);
}

[code].....

View Replies


ADVERTISEMENT

Printing Index Of Output Array

Feb 6, 2014

I want to Display the Index of output Array.

here is the code:
 
import java.util.ArrayList;
import java.util.List;
public class selection {
private static int[] numbers= { 1, 2, 4, 8, 16, 32, 64, 128, 250, 250, 250, 250, 250, 250, 250 };
private static int[] sumsum= new int[numbers.length];
private static int sum= 1759;

[Code] .....

View Replies View Related

String Index Out Of Bounds?

Feb 6, 2014

Ok, so I'm just trying to write a basic little program that reverses the letters in someone's name. I thought I had it down, but I guess not. Here's the code, and the error I'm getting is:

java.lang.StringIndexOutOfBoundsException:
String index out of range: 11 (in java.lang.String)
(11 is the length of the name I'm inputting)
import java.io.*;
import java.util.*;

[code]....

View Replies View Related

Error String Index Out Of Range?

Jan 25, 2015

public class op{
  String word = "Hello"; //my variable
  public void reverseword() //My function {
  for(int i =word.length();i>=0 ;i--) {
System.out.println(word.charAt(i));

[code]....

when i call function in main i have this error:

run:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 5
at java.lang.String.charAt(String.java:658)
at javacourse.Car.opname(Car.java:35)
at javacourse.JavaCourse.main(JavaCourse.java:24)
Java Result: 1

View Replies View Related

Setting Int And String To Index In ArrayList

Apr 27, 2015

I would like to know how to set a int and a string to the same index in Array list. For example index 0 would have 5 and "Apple".

View Replies View Related

String Index Out Of Bounds Exception

Apr 8, 2015

I get the following error when trying to run my hangman program:

Exception in thread "main" java.lang.StringIndexOutOfBoundsExceptiion.

Why am I getting this error?

import java.util.*;
import java.io.*;
public class hangman {
public static void main(String[] args) throws FileNotFoundException{
Scanner kb = new Scanner(System.in);
String filename;

[Code] .....

View Replies View Related

String Index Out Of Range Error?

Jul 25, 2014

this method is supposed to compute the decimal value of an entered binary the first 2 lines are causing a string out of index error.

public static int computeDecimalValue(String num)
{
int end = num.length();

[Code]....

View Replies View Related

Error String Index Out Of Range

Jul 2, 2014

I write a code but it show a error message

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
ex out of range: 10
at java.lang.String.charAt(String.java:658)
at StringChar.main(StringChar.java:11)

Code :

class StringChar{
 public static void main(String ss[]){
String str="HelloWorld";
int a;
System.out.println("String is = " + str);
a=str.length();
System.out.println("String is After Reverse");
for(int i=a;i>=0;i--)
System.out.print(str.charAt(i));
}
}

View Replies View Related

How To Avoid String Index OutOfBounds Exception

Feb 16, 2015

The method I am trying to successfully write is startsWith(String s1, String s2)

The intention of the code is to return true if s2 starts with the string s1, and false otherwise. For example,

x.startsWith("Maplestory","Maple"); Should return true.

This code partially works, depending on the values entered into it. When it is supposed to return true, it does do this. When it is meant to return false, I get a StringIndex OutOfBounds Exception.
 
public class CC02{
String remove1(char c, String s){
String to_return="";
while(true){
if(s.equals(""))
return to_return;

[Code] ....

The method I have written uses one other method from my code, which is "reverse". Any way to return false without getting this error.

View Replies View Related

Arithmetic Operation - String Index Out Of Range Error?

Nov 17, 2014

I am trying to write a program which asks the user to enter two numbers and then do the arithmetic operation based on user's input . No compiling errors but when I run the program I keep getting "StringIndexOutOfBounds" error .
 
class arithmetic { 
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int ent1 = 0;

[Code]....

View Replies View Related

Program Is Working But String Index Out Of Range Error

Sep 5, 2014

My Computer Programming teacher has given the class a problem that requires the use of var.charAt(), var.length() and while/for. Basically, the problem is that we have to create program that'll show a mirrored or reverse version of the entered word. Like for example, if your input is the word "Hello" (the quotation marks aren't included), the output will be "olleH".

Here's the code:

import java.io.*;
public class StringMirror
{public static void main (String [] args) throws IOException
{BufferedReader scan = new BufferedReader (new InputStreamReader(System.in));
String enteredWord = "";
int lengthOfTheWord = 0;
int lengthOfTheWordMinusOneVersion = 0;

[code]....

It is working, but the problem is that after the output, there's this error that says String index out of range: -1.

the program is working but I kind of wanted it to have no errors in the end.

View Replies View Related

Method To Format Telephone Numbers - String Index Out Of Range Error

Jan 25, 2015

I'm trying to put together a method that formats telelphone numbers, but there's a part of my code that not working. If I enter (305)912-5458 into the variable phoneNumb I get an index is out of range error. I added a lot of system out messages so that I can try to get an idea of why the code was crashing.

public static void main(String[] args) {
int intBegin = 0;
int intEnd = 1;
int length;
String charact;
StringBuilder numbuilder = new StringBuilder();

[Code] .....

The error message I'm getting is:

run:
The length is 13
intBegin is at 0
intEnd is at 1
index is at 0
Charcter ( was not inserted

[Code] ....

View Replies View Related

Code Not Printing String Literal

Sep 18, 2014

I need to use print not println to declare stuff and I need to have string literals I think that's /n. Now when I compile it just shows row1, row2 ect. Why does it work like that?

public class art {
public static void main(String[] args) {
//local variables
String row1= "***********************";
String row2= "** *** *** **";
String row3= "** ***** ***** **";

[Code] ...

View Replies View Related

Taking String And Printing Only The Digits?

Apr 26, 2015

This is the code that I have so far, It will only print out the digit if it is entered first..How to I get it to print out all digits? and I am getting an error that the c is not initialized

import java.util.*;
//Write a program that prompts the user for some text. Output only the digits in that text. Hint: Use a loop and the Character.isDigit method.
public class Q1
{

[Code].....

View Replies View Related

String Inputs And Outputs - Printing Information To Console

Mar 22, 2014

Write an application that asks the user to enter his/her first name, last name, birthday, and where you born (all fields type String) and prints their information to the console. Use the techniques discuss in class. The data must be encapsulated. The program must be coded in Notpad++ and compiled in the Command Prompt.

Output should be like this:

Welcome!

What is your first name? Carlos

What is your last name? De La Torre

When is your birthday? 08/12/1979

Where did you born? Puerto Rico

First Name: Carlos

Last Name: De La Torre

Birthday : 08/12/1979

Born in : Puerto Rico

This is what I have so far :

package myinfo;
import java.util.Scanner;

public class MyInfo {
private String name;
private String lastName;
private String birthday;
private String birthPlace;

[Code] ....

View Replies View Related

Converting Long Values To String - BufferedWriter Not Printing Desired Results

Apr 20, 2014

Currently, my program converts Long values to String. And when I test it out, it do print out the correct output. However, when the converted String value is passed over to be written in a text file, it seems that BufferedWriter isn't printing out the outcome that it's supposed to be.

saltVs = Long.toString(saltV);
System.out.print(saltVs); //will print out 79723172

Now the problem is here...It only prints out the last digit of the String value (instead of 79723172).

Here is my FileWriter/BufferedWriter part.

Why is that when I run my program using command prompt, it prints out the output that I wanted, but however when it comes to writing to the file, it doesn't come out right.

View Replies View Related

JSF :: Row Index In UI - Repeat Tag

Feb 7, 2009

I am using ui:repeat tag to iterate over a list. Now in that I need to do some processing based on the current iteration index like we have in a normal for loop. I have to do some processing based on the current iteration index. How can I get that.

View Replies View Related

Index Out Of Bounds

Oct 17, 2014

Code is supposed to count number of Words in a String between A-Z and a-z, i am aware there are many methods to do this more efficiently, but i would prefer to do it using the methods shown.

class
// Purpose : 1) Write a program which will input a string from the
//keyboard, and output the number of separate words,
//where a word is one or more characters separated by
//spaces. Your program should only count as words groups
//of characters in the ranges A..Z and a..z
//
{
public static void main(String args[])

[code]....

View Replies View Related

Array Index Out Of Bounds

Oct 21, 2014

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.awt.event.*;

[Code] ......

Just cant see where the array is out og bounds the array ButtonList has 9 buttons....

View Replies View Related

Getting The Index Of A Matrix Of Buttons

Dec 7, 2014

I am attempting to get the x and y coordinate of a matrix of buttons. I have googled my way to failure and read the docs and I think I am traveling of track.

Below is where I create a matrix of buttons via Swing

public class View extends Mybuttons{
 private static final long serialVersionUID = 1L;
JFrame frame;
JPanel matrixPanel, optionsPanel;
Mybuttons[][] matrixBtn;

Later in this class:

JPanel matrixPan(){
matrixBtn = new Mybuttons[25][25];
JPanel panel = new JPanel();
panel.setSize(550,550);
panel.setLayout(new GridLayout(25,25));
//creating a 25x25 matrix of buttons

[Code]...

In the controller class I am trying to get the index of each button in the getUnvisitedChildNode method. I need to do this so I can search the buttons around the button passed to it and check if they are been visited yet. Below getUnvisitedChildNode you will be bfs (breadth first search).

private Mybuttons getUnvisitedChildNode(Mybuttons b){
//example of some of the things I have tried
int x= Mybuttons.getComponentAt(b);
int y= Mybuttons.indexOf(b);
int j=0;
return b;
}

[Code]...

View Replies View Related

All Of ArrayList Objects Have Been Given Index Of -1

Nov 15, 2014

So I am working on an assignment and ran into an annoying bug. Basically i have a menu that accesses an ArrayList of Videos which may or may not be read from a file, one of the options of the menu is to edit an existing Video. For this I ask the user for the number of the video and it is checked against the list of video numbers if it returns a match, the method gets the index of the Video object and stores it in a temporary variable the user is allowed to edit the details and the object is put back into the ArrayList using the variable and the ArrayList's set() method

My problem is that once i finish editing the details of a video it gives me a indexOutOfBounds exception

On further investigation using a method that goes through the index of every object in the ArrayList using indexOf() i found out that every single object has been given the index of -1 and not 0,1,2,3 etc.. This is my first error and have not expierenced any other before.

The objects do exist because I have read them from a file. I can also add new Objects and view them successfully but they still have the same index . I have checked my syntax and everything and no errors, this happens at run time only.

I have even created some other ArrayLists seperately and debugged them and their index order is fine. I am too far into this project to start over. I've also tried cleaning the project(my IDE is Eclipse).

View Replies View Related

What Is The Starting Index Of LinkedList

May 12, 2014

What is the starting index for linked list, 0 or 1. I know an array starts at 0 so wouldn't a linked list?

View Replies View Related

Difference Between Element And Index?

Apr 17, 2014

Im working on my homework and it mentioned element for one exercise and an index in another, what is the difference, If Any, Between An Element And An Index?

View Replies View Related

How To Swap Matrix From Index

Jan 2, 2015

so I have this matrix

1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16

If the user for example enter the number 2 for index I need to swap the matrix from this index two lines with two line so this is the result what I need

1 2 5 6
3 4 7 8
9 10 13 14
11 12 15 16

View Replies View Related

Randomly Get Index Of Array

Jan 7, 2015

I created and an Array of integers how can I get randomly get/pick the index of each array element.

View Replies View Related

Index Out Of Bound Error

Apr 5, 2014

I'm new to java and I write a simple "Five in a row" game. I have a fixed 13*13 board which contains 169 buttons in an arraylist. Everytime player clicks the button the game set a value of 'x' or 'o' to the arraylist name value. And I have a method named isWon() to check if the it is won or not after player click the button. The game sometime gets and index out of bound exception when checking for whose win.

ArrayList<Character> value = new ArrayList<>();
constructor()
{
for (int i = 0; i < 169; i++) {

value.add(' ');

[code]....

View Replies View Related







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