JavaNoob101
Technical User
At least i think it's charAt.
I started this program to try and make mathmatical designs for characters (don't ask, no job, no school, i get bored) during the summer, and can't figure out why this has been happening:
SAMPLE OUTPUT*************************
Please input a letter to select a print style
a
Please enter the character you wish to print
@
Number of times you wish to print it per line:
4
Number of lines you wish to print:
3
@
Please input a letter to select a print style
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
ex out of range: 0
at java.lang.String.charAt(String.java:558)
at Printshapes.main(Printshapes.java:32)
Press any key to continue . . .
END OUTPUT ERROR ****************
As for the code, i should probably post that too, but it's long. I'm going to put it down anyway, please tell me if there's a better way to post code.
BEGIN CODE *****************************************
import java.util.*;
public class Printshapes
{
public static void main (String[] args)
{
Scanner keyboard = new Scanner(System.in);
//Defining variables
char style = ' ';
char ch = ' ';
String stylestr = " ";
String chstr = " ";
int times = 0;
int rows = 0;
int t = 0;
int r = 0;
//Prompts and inputs
//Do Loop
do
{
style = ' ';
stylestr = " ";
System.out.println ("Please input a letter to select a print style");
stylestr = keyboard.nextLine();
style = stylestr.charAt(0);
if (style == 'a') (A is supposed to print the character a certain number of times on a certain number of lines)
{
System.out.println ("Please enter the character you wish to print");
chstr = keyboard.nextLine();
ch = chstr.charAt( 0 );
System.out.println ("Number of times you wish to print it per line:");
times = keyboard.nextInt();
System.out.println ("Number of lines you wish to print:");
rows = keyboard.nextInt();
for (r = rows; r > 0 ; r--);
{
for (t = times ; t > 0 ; t--);
{
System.out.print (ch);
}
System.out.println();
}
}
else
if (style == 'b')(B was counting up by one per line, to take it one step further)
{
System.out.println ("Please enter the character you wish to print");
chstr = keyboard.nextLine();
ch = chstr.charAt( 0 );
System.out.println ("Number of lines you wish to print:");
rows = keyboard.nextInt();
for (t = 1 ; t > rows ; t++);
{
System.out.print (ch);
for (r = rows ; r > 0 ; r--);
{
System.out.println();
}
}
}
else
if (style == 'f')
break;
}
while (style != 'f');
}
}
END CODE ******************************************
I would just like to know why the error is happening, please do not help with anything else. This is my own project and it's a pride thing.
I started this program to try and make mathmatical designs for characters (don't ask, no job, no school, i get bored) during the summer, and can't figure out why this has been happening:
SAMPLE OUTPUT*************************
Please input a letter to select a print style
a
Please enter the character you wish to print
@
Number of times you wish to print it per line:
4
Number of lines you wish to print:
3
@
Please input a letter to select a print style
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String ind
ex out of range: 0
at java.lang.String.charAt(String.java:558)
at Printshapes.main(Printshapes.java:32)
Press any key to continue . . .
END OUTPUT ERROR ****************
As for the code, i should probably post that too, but it's long. I'm going to put it down anyway, please tell me if there's a better way to post code.
BEGIN CODE *****************************************
import java.util.*;
public class Printshapes
{
public static void main (String[] args)
{
Scanner keyboard = new Scanner(System.in);
//Defining variables
char style = ' ';
char ch = ' ';
String stylestr = " ";
String chstr = " ";
int times = 0;
int rows = 0;
int t = 0;
int r = 0;
//Prompts and inputs
//Do Loop
do
{
style = ' ';
stylestr = " ";
System.out.println ("Please input a letter to select a print style");
stylestr = keyboard.nextLine();
style = stylestr.charAt(0);
if (style == 'a') (A is supposed to print the character a certain number of times on a certain number of lines)
{
System.out.println ("Please enter the character you wish to print");
chstr = keyboard.nextLine();
ch = chstr.charAt( 0 );
System.out.println ("Number of times you wish to print it per line:");
times = keyboard.nextInt();
System.out.println ("Number of lines you wish to print:");
rows = keyboard.nextInt();
for (r = rows; r > 0 ; r--);
{
for (t = times ; t > 0 ; t--);
{
System.out.print (ch);
}
System.out.println();
}
}
else
if (style == 'b')(B was counting up by one per line, to take it one step further)
{
System.out.println ("Please enter the character you wish to print");
chstr = keyboard.nextLine();
ch = chstr.charAt( 0 );
System.out.println ("Number of lines you wish to print:");
rows = keyboard.nextInt();
for (t = 1 ; t > rows ; t++);
{
System.out.print (ch);
for (r = rows ; r > 0 ; r--);
{
System.out.println();
}
}
}
else
if (style == 'f')
break;
}
while (style != 'f');
}
}
END CODE ******************************************
I would just like to know why the error is happening, please do not help with anything else. This is my own project and it's a pride thing.