Hello I’m having issues on my intro to Computer Science Lab Work:
CharacterLine.java: Write a program that prints a line of characters. Prompt the user to enter a character and then ask for a number. If the number is lies than 1 or greater than 80, tell the user then to exit the program. Use a while Loop to print out the character as many times as the number read in.
Example:
Please enter a character: &
Please enter a number: 15
Your line: &&&&&&&&&&&&&&&
Here is my code:
import java.util.Scanner;
public class CharacterLine
{
public static void main(String[] args)
{
Scanner kb = new Scanner (System.in);
int number;
System.out.print("Please enter a character: ");
String character = kb.next();
int charact = character.length();
System.out.print("Please enter a number: ");
number = kb.nextInt();
while ( number <= 80 && number >= 1 ){
if ( number <= 80 && number >= 1 ) {
int bills = (charact * number);
System.out.println("Your line: " + charact++);
}
else {
System.out.println("error.");
}
System.out.println();
System.out.print("Please enter a number: ");
number = kb.nextInt();
}
if ( number > 80 ){
System.out.println("That number is too large");
}
else if ( number < 1 ){
System.out.println("That number is too small");
}
else{
System.out.println("error");
}
}
}
I am having issues in knowing how I can multiply the number that the user inputted and make the output the number times the one letter that the user inputted.
Thanks,
William
You can use loop to iterate for
givennumber of times.. and print the character..The above while loop says: