Reputation:
import java.util.Scanner;
public class main
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
String input, scramble;
System.out.println("Input message to be coded: ");
input = keyboard.nextLine();
System.out.println("Input: " + input);
for (int i = 0; i < input.length(); i++)
{
scramble += scrambleMessage(input.charAt(i));
}
System.out.println("Coded message is: " + scramble);
}
public static char scrambleMessage( char c, int x)
{
int charc = c;
if (!Character.isLetter(c))
return c;
charc = (charc * (charc - 1))/(charc + (charc - 1)) + 5;
return (char)charc;
}
}
When I try and compile this code it says:
: error: method scrambleMessage in class main cannot be applied to given types;
scramble += scrambleMessage(input.charAt(i));
^
I don't understand what it is saying is wrong. The purpose of the program is to take the string entered in main and run it through the scrambleMessage() functions to change the letter up. I run it by running the string on a char by char basis, making each char it's corresponding number then remaking it a char. Not sure what is going on that is giving me this error.
Upvotes: 1
Views: 1448
Reputation: 9872
because your scrambleMessage(char c, int x)
take 2 parameters.you should pass a char and int .since you are not using int parameter remove it
public static char scrambleMessage( char c)
{
int charc = c;
if (!Character.isLetter(c))
return c;
charc = (charc * (charc - 1))/(charc + (charc - 1)) + 5;
return (char)charc;
}
also you should change this line
String input, scramble =null;
to
String input, scramble = "";
because local variables should be initialized before use them and you should avoid null
Upvotes: 0
Reputation: 936
Error say you :
The method scrambleMessage(char, int) in the type main is not applicable for the arguments (char)
,
you need pass char and int , you just pass one parameter.
or edit
public static char scrambleMessage( char c, int x)
to
public static char scrambleMessage( char c)
and i think you have another error like this :
The local variable scramble may not have been initialized
you must change this line :
String input, scramble ;
to
String input, scramble = "";
Upvotes: 1