Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9060471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:14:18+00:00 2026-06-16T15:14:18+00:00

Simple program from DEITLE’s book , read 5 integers and the program should print

  • 0

Simple program from DEITLE’s book , read 5 integers and the program should print line containing that number of adjacent asterisks .i.e (if num = 5 the output *****) .
I have tested the same solution in c++ and it worked fine . yet, here the buffer is holding strange values (50 ?) .
I think the problem is in using the buffer , however i want to know why this is happening?

   /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication1;
import java.io.*;
import java.util.Date;
/**
 * Program that reads five numbers and print starts equal to each number 
 *
 * @author Hassan
 */
public class JavaApplication1 

{


    public static void main(String[] args) 
    {
       int num ; 
       java.io.InputStreamReader  ins= new InputStreamReader(System.in);
       java.io.BufferedReader bfr = new BufferedReader (ins);

       try
       {


       for(int i=0;i<5;i++)
       {
           System.out.println("Please Enter a number");

           num = bfr.read(); 

       System.out.print(num);


             for(int j=0;j<num;j++)
                {   System.out.print("* ");  }
                  System.out.println("\n");


       }    
       } 

       catch(Exception E )
       {System.out.println(E.getMessage());  }



    }
}

EDIT :the problem has been solved , yet the program -out of 5 inputs -is reading 3 only i.e its reading input and ignoring the next one
enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:14:20+00:00Added an answer on June 16, 2026 at 3:14 pm

    You’re reading a byte, which will just be the ascii value of the first available character. 50 is ‘2’ in ascii. You probably want to read, and parse, a number entered as text.

    If you use readLine() instead of read(), into a String, you can then use Integer.parseInt() to get the real value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple program it has a function to read a line from
I am trying to write a simple program that reads integers from a data
Write a simple program that reads a line from the keyboard and outputs the
I have a simple program that reads data from a PNG into a 2D
I need to write a simple program that records all the input from parallel
I have a simple program from a C programming book, and it's supposed to
I am trying to make a simple program that will subtract an object from
So I made a very simple program that counts down from 99 (sings 99
I have a simple program that takes an ID number and prints information for
Assume I have simple program (executable compiled from a C program)that provides text information

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.