java - Counting the characters of a string and than placing the value inside a for loop -
i taking introductory java programming course , have been setting following exercise:
write program can ask series of questions array of strings. should print line of stars under question, line of stars same length question printed above it.
below code have written. starlineexercise class features method called starline, have started write below. starline method needs print many "*" characters in each of previous system.out.println commands.
i have tried create string object each question, count of that, , place loop, eclipse gives me error saying count variable can not resolved.
import java.util.scanner ; public class starlineexercise{ public static void main(string[] args){ scanner sc = new scanner (system.in); system.out.println ("please enter name"); starline(); string name = sc.nextline(); starline(); system.out.println("pleae enter age"); starline(); int age = sc.nextint(); system.out.println("your name " + name + " , age " + age); } public static void starline(){ (int = 0; < 20; i++); system.out.println("*"); } system.out.println(""); } }
you need alter few things in code:
- save question in
string
before printing it. - change
starline()
method take parameter, can pass in length ofstring
. - change hard-coded
20
instarline()
method use parameter.
Comments
Post a Comment