java - Having difficulty calling a method -


i have feeling answer's right under nose, n00b-ness java has me chasing tail. first part, i'm suppose ask user in put 2 strings, compare them, , state number of characters in first string. second part, i'm suppose ask user enter position bearing in mind first character starts @ zero, , code's suppose state character @ position.

i think code first part pretty clean, need on second part. i've written method @ bottom, don't know how call it. keep getting error message in compiler. haven't gotten chance test method because of error, if see wrong that, appreciated. in advance!

import java.util.scanner;  public class stringcode1 {    public static void main(string[] args)    {     string string1, string2;     int pos;          scanner stdin = new scanner(system.in);          system.out.print("enter first string: ");         string1 = stdin.next();         system.out.print("enter second string: ");         string2 = stdin.next();          if (string1.compareto(string2) > 0)     {        system.out.println(string1 + " less " + string2);     }         else if (string1.compareto(string2) == 0)     {        system.out.println(string1 + " equal " + string2);     }         else if (string1.compareto(string2) < 0)     {        system.out.println(string1 + " greater " + string2);     }     system.out.print("number of characters in " + string1 + " " );             system.out.println(string1.length() );      string = showchar();    }     public static char showchar(string string1, int pos)    {     scanner stdin = new scanner(system.in);      system.out.println("enter position noting first character @ 0: ");     string1 = stdin.nextline();     pos = stdin.nextint();      system.out.print("character @ position" + pos + "in " + string1);      system.out.print("is: ");      system.out.println(string1.charat(pos));     }     } 

string = showchar(); 

in above line, trying assign type, invalid expression. additionally, method showchar requires 2 arguments , you're trying call none.

one more error showchar has return type of char no return statement. either make void method, or have return (presumably string1.charat(pos)).

so, you'll have find argument showchar should , then, if value of showchar supposed return char, assign variable of type, so:

char c = showchar(string1, yourindex); 

or, if it's going void:

showchar(string1, yourindex); 

...where yourindex value want pass pos parameter in showcar.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -