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
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)); } }
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;
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.
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
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++) {
I am getting error array index out of bound ... Error detail is :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at abhiExample.arraytwodiam.main(arraytwodiam.java:27 )
And program is
Java Code:
package abhiExample; import java.util.Scanner; public class arraytwodiam { public static void main(String [] args) { char[][] Atrace={}; int i,j,k,l=0,row ,characters;
I have two codes of needed to run but after processing, the said above error is preventing it from getting the general output of the code.I can't seem to find my errors or I don't have any clue at all, if perhaps you know, here's the codes:
Error : PHP Code:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at simpleOutput.main(simpleOutput.java:13) public class simpleOutput { public static void main(String args[]){ int n = Integer.parseInt(args[0]); for(int i = 1; i <= n; i++){ } for(int i = 1; n <= i; n++){ System.out.print((i*n)+" ");
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); }
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.*;
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.
I am currently trying to split the string "EAM est" between the part. I have gotten the code to work if the was a -. But I can't see why the error is occuring
I'm writing basically my first program for school. I've written small ones, following instructions, but this is the most vague. I'm having issues. I can't figure out what the error means. I'm not done with the code, but I think the ArrayList is throwing me off. I'm trying to gather user input and sum the total. Here's the code:
package graduationplanner; import java.util.ArrayList; import java.util.Scanner; import java.lang.Double; public class GraduationPlanner { public static void main(String[] args) {
I have this error that keeps coming up any time I select one of my buttons. It actually doesn't hinder the performance of the project, everything works. But I am concerned I missed something and errors are never a good sign.On a slightly different note, I would like to figure out what the best way to format my output would be? I would like it to display as "100.00 F". I have a couple ideas on how to get the F symbol (or other symbol) by inserting something like
String degreesymbol = "F" or whichever it is and then returning that in the output string later. I can't get the decimal formatted correctly and I don't know how to print the degree symbol.Here is the code
I'm having a small error with my code, it is getting rid of the first letter of the string after the first line printed.
import java.util.*; public class PrintPyramidName { public static void main(String[] args) { System.out.println("What is your name?"); Scanner input = new Scanner(System.in);
I am having issues with the program below everything works but I can't figure out a way to add code that if a user just hits enter without inputting anything it says "entering in nothing is not a valid choice" I am stuck on how to compare a int to a string ...
//import statements import java.util.*; //for scanner class // class beginning public class Guess { public static void main(String[] args ) { //Declare variables area
public void addEvent(ActionEvent evt) { uname = Util.getUname(); boolean a = EventDAO.add(this); if ( a) { message = "Event has been added!";
[Code] ....
While executing this..i get the following error: ORA-01861: literal does not match format string. Could it be due to any mismatch in date format (chrome browser automatically takes date in the format mm-dd-yyyy )? If yes, how do I resolve it? (I'm using Oracle database)
import java.io.InputStreamReader; import java.util.Scanner; public class FinalCombinations { public static void main(String[] args){ //Read number of values System.out.println("Enter the no of values");
[Code] .....
I am getting output like this
Enter the no of values 4
Enter the values 1 2 3 4
Enter the number for combination 2 C(4,2)=6 1 1 2 1 1 3 1 1 4 2 2 3 2 2 4 3 3 4
where as I want output like this..wit one array 1 2 1 3 1 4 2 3 2 4 3 4
Given a string, compute a new string where identical chars that are adjacent in the original string are separated from each other by a "*". My implementation :
package com.tcs.dash; public class StringBuild { public String edit(String userIp){ StringBuilder builder = new StringBuilder(userIp); String replaceText = ""; for(int i = 0; i < builder.length() - 1; i++){ if(builder.charAt(i) == builder.charAt(i+1)){ replaceText = builder.charAt(i) + "*" + builder.charAt(i+1); builder = builder.replace(i, i+1, replaceText); } } return builder.toString(); } }
I am getting error at line 13. An exception actually.
I/P given = aaaa
Console:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Unknown Source) at java.lang.AbstractStringBuilder.expandCapacity(Unknown Source) at java.lang.AbstractStringBuilder.ensureCapacityInternal(Unknown Source) at java.lang.AbstractStringBuilder.replace(Unknown Source) at java.lang.StringBuilder.replace(Unknown Source) at com.tcs.dash.StringBuild.edit(StringBuild.java:13) at com.tcs.dash.StringBuildExample.main(StringBuildExample.java:14)