+ 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.

7th Feb 2017, 12:42 PM
Artjola Meli
Artjola Meli - avatar
9 odpowiedzi
+ 2
Thank you Gavin
7th Feb 2017, 1:24 PM
Artjola Meli
Artjola Meli - avatar
+ 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"); } }
7th Feb 2017, 1:30 PM
Ghauth Christians
Ghauth Christians - avatar
+ 2
Okay I fixed it now, the error was secret.length and it should be secret.length(). Classic mistake of mine lol
7th Feb 2017, 1:31 PM
Ghauth Christians
Ghauth Christians - avatar
+ 2
Thank you i appreciate it.
7th Feb 2017, 1:34 PM
Artjola Meli
Artjola Meli - avatar
+ 1
yes,tryed hard but i am having some problem
7th Feb 2017, 1:13 PM
Artjola Meli
Artjola Meli - avatar
+ 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
7th Feb 2017, 1:23 PM
Artjola Meli
Artjola Meli - avatar
+ 1
My code seems to be incorrect so I'll quickly figure it out and correct what's wrong
7th Feb 2017, 1:27 PM
Ghauth Christians
Ghauth Christians - avatar
+ 1
Thank you i appreciate it.
7th Feb 2017, 1:33 PM
Artjola Meli
Artjola Meli - avatar
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.
7th Feb 2017, 1:20 PM
Jean-Luc Wilkins