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:

  1. save question in string before printing it.
  2. change starline() method take parameter, can pass in length of string.
  3. change hard-coded 20 in starline() method use parameter.

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -