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

  • SEARCH
  • Home
  • 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 7975497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:39:26+00:00 2026-06-04T08:39:26+00:00

I am currently trying to create a volume, Area, Surface Area, and perimeter calculator

  • 0

I am currently trying to create a volume, Area, Surface Area, and perimeter calculator but I have run into little problem

package Volume;

public class C {
  static double r;
  static double h;

    static double volume() {
      return (25/7.957747154)*(r*r)*h;
    }

}

The data Class

package Volume;

import java.io.IOException;
import java.util.Scanner;

public class VC {
  public static void main(String args[]) 
    throws IOException {
      char s2;  
      char s1;
      Scanner first = new Scanner(System.in);
      Scanner second = new Scanner(System.in);
      a: {
      System.out.println("Chose your Type: \n1.Volume \n2.Area \n3.Surface Area \n4.Perimeter \n5.Exit \nPlease type the number of your option.");
      s1 = (char) System.in.read();
      switch(s1) {
        case '1':
        System.out.println("Chose Your Shape: \n1.Cylinder \ntype the number");
        s2 = (char) System.in.read();
        switch(s2) {
          case '1': 
          System.out.println("Raidius?");
          Volume.C.r = first.nextDouble();
          System.out.println("Height?");
          Volume.C.h = second.nextDouble();
          Double v;
          v = Volume.C.volume();
          System.out.println("The Volume is:" + v);
          break a;
       }
       case '5':
       System.out.println("GoodBye");
     }
   }
 }
}

The Main Class

The problem I run into is after I finish the first switch statement instead of pausing to read the char it skips that whole block and goes to case ‘5’:
ending the program before anything is done.

Could someone please explain this to me?

  • 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-04T08:39:27+00:00Added an answer on June 4, 2026 at 8:39 am

    IO buffering is a source to many problems, I would suggest that you:

    1. Access System.in only through a Scanner (e.g. no System.in.read)
    2. Create only a single Scanner for he same stream (e.g., only first, no second)

    Some more explanation:

    You are accessing the standard input stream (e.g. the user input) through 3 different objects:

    • first – System.in wrapped by Scanner
    • second – System.in wrapped by Scanner
    • Directly in some places, for example s2 = (char) System.in.read();

    Instead, create only one Scanner and use it for all the reads from System.in

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

Sidebar

Related Questions

What I currently have I'm currently trying to create a little download manager in
I'm currently trying to create FULLTEXT indexes into my database (Microsoft SQL Server 2005).
I'm currently trying to create a little remote-app for Android to control a MediaPlayer
I am currently trying to create a mail list that stores emails into an
I am currently trying to create two simple one-to-one mappings using Hibernate but somehow
I'm currently trying to create a little C/C++ program which emulates a key-press on
I'm currently trying to create my own theme but I can't figure out how
I'm currently trying to create a template in TextMate. The template is very basic:
I'm currently trying to create an email application using Rails and Sendgrid. This application
I'm currently trying to create a program that estimates location based on signal strength.

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.