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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:38:06+00:00 2026-06-04T10:38:06+00:00

This is more or less my first java project. I can’t get my while

  • 0

This is more or less my first java project. I can’t get my while loop to work properly. It seems to loop as many times as the integer I input for my first option. But I want it to for my second one. My computer teacher isn’t very helpful at all.

import java.awt.*;
public class Summative extends JApplet
{
    int n; //first choice variable
    int t; //time variable
    int integer; //integer input
    int x=0; //count variable
    int y=50; //test

    public void init() //Initialize method
    {
        setSize(1000, 800); //Set size

        Container c = getContentPane();
        c.setBackground(Color.GREEN); //Set background
    }    


    public void paint(Graphics g) 
    {
        super.paint(g); //Start paint method

        g.setFont(new Font("Veranda", Font.PLAIN, 20));
        g.setColor(Color.BLACK);

        g.drawString("Hello", 250, 25); //top display message

        String number = JOptionPane.showInputDialog("Would you like a custom loop count or an infinite? 1.  Custom   2. Infinite"); //test choice
        n = Integer.parseInt(number);
        while (n<0 || n>2);

        if (n==1);
        { 
        }
        do
        {
            String number2 = JOptionPane.showInputDialog("How many times would you like to loop?");
            integer = Integer.parseInt(number);
        }while (integer<0 || integer>99999);


        while (x < integer)
        {   
            g.drawString("hi", 200, y); 

            x+=1;
            y = y+40; //test

        }
    }
}
  • 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-04T10:38:07+00:00Added an answer on June 4, 2026 at 10:38 am

    I think you meant this

    integer = Integer.parseInt(number);
    

    to be

    integer = Integer.parseInt(number2);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

first of all, this is more or less my first GUI and ive learned
So this is my first time posting here but I'm more or less stumped.
I use C# code more-or-less like this to serialize an object to XML: XmlSerializer
I am programming in Java but this is a more of a design question
This is more or less copy pasted from boost docs and I keep getting
In Java I have a string like this 0564\n5523\n5445\n8596 and I'd like more or
This is more or less a general question and not about any specific ORM
I have more or less exactly the same error as in this post ,
I'm writing my first Android app, which is more or less going to be
I want to know this more in detail. Is it a realtime scheduler? An

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.