Need help using subString [closed] - java

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
public class project5{
public static void main(String args[]){
String[] storage = {"123457897", "123456","654654654"};
int current;
current = Integer.parseInt(storage[1].subString(1,5));
System.out.println(current);
}
}
So I'm trying to, as an exercise, just get the first 5 numbers in the first thing of the array and parse it as an integer and store it as the variable current. It gives me the error:
test.java:5: error: cannot find symbol
current = Integer.parseInt(storage[1].subString(1,5));
^
symbol: method subString(int,int)
location: class String
1 error
What is it that I'm doing wrong?

There is no subString method on the String class. There only is substring (all lowercase).
http://docs.oracle.com/javase/7/docs/api/java/lang/String.html
For variable, class and method names casing matters.

Related

Split function giving incorrect result in java [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
import java.util.*;
class Solution {
public static void main(String d[]) {
Scanner sc=new Scanner(System.in);
String s0=sc.next();
String p[]=s0.split(" ");
System.out.println(p.length);
}
}
I am using jdk version 8 and when i am giving input as "hello world java", it is printing length as 1 ,whereas it should print the length as 3,please help me in resolving this
Scanner.next() will get the input from the user till a space is encountered. For the input "hello world java" it only assign "hello"
If you want to include spaces also use Scanner.nextLine()

Beginning java; compile time error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am taking an intro to java class, and I have to make a chicken class with a method walk(). I have everything done, but the method walk().
public void walk();
{
System.out.print( Chicken + "is walking." );
}
This is what I'm trying, and I am getting a compile time error
Chicken.java:25: error: missing method body, or declare abstract
public void walk();
Chicken.java:27: error: cannot find symbol
System.out.print( Chicken + "is walking." );
symbol: variable Chicken
location: class Chicken
Any help would be appreciated, and thanks!
That is because of a semi colon after walk(). It denotes the end of statement, all you need to do is to remove it and the code will compile. E.g.
public void walk(){
System.out.print( Chicken + "is walking." );
}

"Not a statement" Compile Error in java [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am having a problem when I am trying to compile a pattern program. I am creating this program in BLUEJ and when I am trying to compile it shows the error : "not a statement"
class pattern
{
public static void main()
{
int p=0;
for(int i=1;p=1;i<=4;i++,p++)
{
for(int j=1;j<=i;j++)
{
System.out.print(Math.pow(p,2);
}
System.out.println();
}
}
}
What is the problem?
A couple of issues there, the main one being this:
for(int i=1;p=1;i<=4;i++,p++)
// ^ ^ ^
The for statement consists of three, not four, parts separated with ;. I suspect you wanted
for(int i=1,p=1;i<=4;i++,p++)
// ^--- comma here
Separately, I believe you have to specify the argument to main even if you're not using it, so:
public static void main(String[] args)
In a comment on the qustion, cadrian pointed out a further problem:
System.out.print(Math.pow(p,2);
// Missing ) here ------------^

Illegal format string in TextIO.putf() method aka wrong Array Type? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I guess its a rather simple question but i just cant find my mistake.
int[] myIntArray = new int[20];
myIntArray[5] = 5;
int a = myIntArray[5];
TextIO.putf("arr[i]: d%",a );
The error I get is Illegal format string in TextIO.putf() method.
So I assume the value at the index 5 is not an int?
The error message says exactly what the problem is: your format string is wrong. You probably meant %d (or better yet, %d%n to add a newline).
The format string elements are in the form
%[modifiers]type
not
something%
Change d% to %d.

Java can't find the 'equal' method

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 days ago.
Improve this question
I tried to check if a property was equal to a string but I keep getting this error
Code:
if (prop.getProperty("quit").equal("true")) {
}
Error:
cannot find symbol
symbol: method equal(java.lang.String)
location: class java.lang.String
The method name is equals not equal.

Categories