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 8699867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:03:02+00:00 2026-06-13T02:03:02+00:00

Here is my code: import java.util.Scanner; public class BankAccount1 { public static void main(String[]

  • 0

Here is my code:

import java.util.Scanner;

public class BankAccount1
{
public static void main(String[] args)
{
    Scanner input = new Scanner(System.in);

    char pickup;
    char size;
    char type;
    String name;

    double cost=0.0;
    int i;


    for (i=0; i<2; i++)
    {
    System.out.println("What is your name?");
    name = input.nextLine();

    System.out.println("size of pizza: ");
    size =  input.next().charAt(0);

    System.out.println("type of pizza: ");
    type = input.next().charAt(0);

    System.out.println("pick up or delivery?");
    pickup = input.next().charAt(0);


    if(size == 'S' || type == 'V') {cost = 10.0;}
    else if(size == 'M' || type == 'V') {cost = 12.25;}
    else if(size == 'L' || type == 'V') {cost = 14.50;}
    else if(size == 'S' || type == 'C') {cost = 7.0;}
    else if(size == 'M' || type == 'C') {cost = 8.0;}
    else if(size == 'L' || type == 'C') {cost = 9.0;}


    if(pickup == 'D'){
    cost=cost+1.50;
    System.out.println("Name: "+name+". Your cost is: "+cost);}
    else { 
    System.out.println("Name: "+name+". Your cost is: "+cost);}


    } 

}

}

I have a for loop in my code, and it asks the name, size, type and pickup. The first time it is run, it asks all fields to be entered, but for the 2nd time, the name field does not let me input the name for some reason, it prints the “What is your name?” but it does not let me enter the name…? can someone tell me why?
Thanks.

this is what it looks like: https://i.stack.imgur.com/eb1BA.jpg

  • 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-13T02:03:03+00:00Added an answer on June 13, 2026 at 2:03 am

    Due to the fact that

    input.next()
    

    does not consume newline characters, these get passed passed back to your loop and does not allow a value to be entered. You would need to add:

    for (i = 0; i < 2; i++) {
       // existing input.next() statements in here
      ...
    
       input.nextLine();
    }
    

    at the end of the for loop to fix.

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

Sidebar

Related Questions

Here's my code: import java.util.Scanner; public class Arrays { public static void main(String[] args)
Here is my code: import javax.swing.*; import java.awt.*; public class PanelModel { public static
Here's my code: import java.util.Scanner; class Graph{ boolean [][]array; int N; Graph (){ array
Wen I have this code: import java.util.Scanner; import java.util.Arrays; public class Ex02 { /**
Here is the code: import javax.swing.*; import java.awt.event.*; import java.awt.*; public class TestGrid {
Here I found this code: import java.awt.*; import javax.swing.*; public class FunWithPanels extends JFrame
Here is a simple piece of code: import java.io.*; public class Read { public
// Here's my code: Main Class: import java.awt.*; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import java.awt.image.BufferStrategy;
Here is the server code package echoserver; import java.net.*; import java.io.*; public class EchoServer
So, I'm getting stuck with this piece of code: import java.util.InputMismatchException; import java.util.Scanner; public

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.