Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

User input is out of bounds.

$
0
0
I am making a program that gives the area of a specific shape. I have:

    if(z == 1)
    {
      System.out.println("Enter the radius of the sphere: ");
      int y = scan.nextInt();
      
      System.out.println("The volume of the Sphere is: ");
      System.out.println((4/3) * pi * Math.pow(y,3));
    }
    
    else if(z == 2)
    {
      System.out.println("Enter the length of one side of the cube: ");
      int x = scan.nextInt();
      
      System.out.println("The volume of the Cube is: ");
      System.out.println(Math.pow(x,3));
    }



If the user input anything but 1 or 2, I want it to say try again and start just that step over. How would I do that? Thanks.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>