1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Anton [14]
3 years ago
6

There is an application which inputs hundred numbers from the user, if user enters a positive number it increments valid numbers

count. But if a user enters other than integer it terminates. You are required to make changes in given code such that instead of termination it shows message “input is not valid” and re input a number. importjavax.swing.*; publicclass QuestionNumber4 { publicstaticvoidmain(String[] args) { intcountValidNumber=0; int num; for(inti=0;i 0){ countValidNumber++; } } System.out.println("Valid Numbers Are:"+countValidNumber); }
Computers and Technology
1 answer:
Sveta_85 [38]3 years ago
6 0

Answer:

Following are the correct code to this question:

import java.util.*;//import package

public class QuestionNumber4 //defining class  QuestionNumber4

{

   public static void main(String[] args)//defining the main method

   {

       int countValidNumber=0,n=0;//defining integer varaible

       int num[]= new int[100]; //defining integer array num

       Scanner ob=new Scanner(System.in);//creating Scanner class Object

       try //using try block

       {

       for(int i=0;i<100;i++)//defining loop to input 100 values

       {num[i]=ob.nextInt();//input value in array

        n=n+num[i];//add number

        countValidNumber++;//count input value

       if(n<0){}}//defining if block to check another value

       }

       catch(Exception e) //catch block to handle Exception

       {

       System.out.println("input is not valid");// print message    

       }

   System.out.println("total intered number are: " + countValidNumber);//print times of input value  

   }  

}

Output:

2

5

7

9

o

input is not valid

total intered nyumber are: 4

Explanation:

following are the description of the above code:

  • In the above program code, a class "QuestionNumber4" is declared, inside the class main function is declared, in this method two integer variable "countValidNumber, n" and an integer array "num" is declared.
  • In the next step, the scanner class object is created to input the value from the user and passed into the try-catch block.
  • In the try block, we input values with the help of loop and in the catch block, we handle there exception and at the last, we print times of input, when user input numbers.  
You might be interested in
On the Format tab, in the Shape Styles group, there is the option to change the _____. a. Shape Effects b. Shape Fill c. Shape O
makvit [3.9K]
Hey there! Hello!

The answer to this problem will be D, "All Of The Above." I've attached a picture that shows the Shape Format tab in Microsoft Word. You can see in the dropdown that there's options for all three of your listed choices: Shape Fill, Shape Outline, and Shape Effects. 

I hope this helped you out! Feel free to ask me any additional questions if you have any. :-)

6 0
3 years ago
Can someone help me write an algorithm and a flow chart pls for question 3
emmainna [20.7K]

for i in range(20, 51, 2):

      print(i)

6 0
3 years ago
PLEASE HELP THIS IS CONFUSING ME
Artemon [7]

Answer:

The answer is:

Yes, because Antonio clearly copied someone else's words.

Explanation:

It is still forbidden to plagiarize Wikipedia despite it being a Open-Source Data base of information. This means, unless you directly cite in a bibliography or with in-text citations, the article, the author, and everything else needed in the proper citations for the format, it is plagiarism.

3 0
2 years ago
Read 2 more answers
____ software is used to block unwanted e-mail and is available at many levels.
Anika [276]
Anti-spam <span>software is used to block unwanted e-mail and is available at many levels.</span>
3 0
3 years ago
Before you insert a page break, what should you do? select the font you want to use for the text that comes after the page break
Triss [41]
Put the insertion point where you want the page to break is what I would write.
7 0
3 years ago
Other questions:
  • Which of the following will most likely result in a decrease in population?
    11·2 answers
  • To make sure that you do not get too tired when typing for long periods, how often should you get up and stretch? Every 15 minut
    9·1 answer
  • Which information is considered free for use?
    9·2 answers
  • From the following list choose all the tasks an operating system performs.
    5·2 answers
  • What are the two types of formulas in excel
    9·1 answer
  • Vannevar Bush imagined a desktop computing machine that would allow people to access data stored in various information centers
    13·1 answer
  • if a user has one column in a table and would like to make it into two columns which command should be used
    13·1 answer
  • How is internet connection made possible.​
    7·1 answer
  • Which of the following is not a key component of a structure?
    5·1 answer
  • Can you please help me with this crossword puzzle, I am having trouble with numbers 5 down and 22 across.
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!