+ 1
How ca i do this problem
it sais to write a program that ask the user for a secret message.then print out how many characters are in the secret message and a secret number. the secret number is calculated by multiplying the number of characters times 2 and adding 7.
9 odpowiedzi
+ 2
Thank you Gavin
+ 2
Hmm.. sounds like homework, but I'll give you this one for free
Solution: (Java)
import java.util.Scanner;
class MyClass{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String secret = sc.nextLine();
int secretNum = (secret.length() * 2) + 7;
System.out.println("There are " + secretNum + " characters in your secret message");
}
}
+ 2
Okay I fixed it now, the error was secret.length and it should be secret.length(). Classic mistake of mine lol
+ 2
Thank you i appreciate it.
+ 1
yes,tryed hard but i am having some problem
+ 1
i have just started to use java, it is a bit difficult for me. When i first downloaded java and starte using it it said that my c:\Programs its not recognized as internal and external command
+ 1
My code seems to be incorrect so I'll quickly figure it out and correct what's wrong
+ 1
Thank you i appreciate it.
0
Use scanner to get the input from the user. Then use the string that you get from the user and print out its length. You should know how to do math so thats easy.