I'm trying to get a user to input a char and an int to create a box visual using that int. I tried to use Character.parseChar, and realized that wasn't possible. How can I get user input of a char value?

Below is my code.

import java.io.*;

    public class Program10{
        
        public static void main(String args[])
        throws java.io.IOException
            {
                BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                System.out.print("Enter the side of the square: ");
                int inputa = Integer.parseInt(br.readLine());
                System.out.print("Enter any character: ");
                int inputb = Character.parseChar(br.readLine());
                squareOfAsterisks(inputa);
                squareOfAsterisks(inputa, inputb);
                
                
            }
            
           
          public static void squareOfAsterisks(int x){
              for(int r=0; r<x; r++){
                    for(int c=0; c<x; c++){
                        System.out.print('*'+" ");
                    }
                    System.out.println();
                }
            }
          public static void squareOfAsterisks(int x, char y){
                System.out.print("Enter any character: ");
                input = Charater.parseChar(br.readLine());
                for(int r=0; r<x; r++){
                    for(int c=0; c<x; c++){
                        System.out.print(yt+" ");
                    }
                    System.out.println();
                }
            }
        }

Recommended Answers

All 3 Replies

question?
At the bottom of your code you have this:

for(int c=0; c<x; c++){
                        System.out.print(yt+" ");

What is the "yt"?

What would this be in c#?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.