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]
4 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]4 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
What are table buffers?
laiz [17]

Answer:

Table buffers are tools used to avoid the process of accessing a database in servers.

4 0
3 years ago
Among the aforementioned parts, the FLASH DRIVE is the most common. Why do you think a flash drive will be essential for you as
zhuklara [117]

Answer:

They can be used to store homework, presentations, research, papers, essays and etc. They can be used to hand out homework assignments, course information or notes

4 0
3 years ago
There are 4 classrooms for fifth grade and 4 classrooms for sixth grade at a school. Each classroom has 20 students. A teacher i
olga_2 [115]

Answer:

what do you want

Explanation:

there are 160 people in all if thatś what you want

5 0
3 years ago
Read 2 more answers
To what extent are such practices permitted today under existing laws and codes of behavior?
11111nata11111 [884]
Maximum fine that a hearing panel can impose for an ethics violation is increasing to $15,000.
5 0
3 years ago
How do you print a document?
Anton [14]
Press ctrl +p and select the printer name then press print
5 0
3 years ago
Read 2 more answers
Other questions:
  • For microsoft word tabs are very useful when you want to
    13·1 answer
  • Critical Infrastructure and Key Resources (CIKR) are potential terrorist targets. CIKR might include: Select one: 1. All telecom
    14·1 answer
  • In terms of in-house custom engines versus third-party engines (like Unity), what has changed today from decades ago, and why?
    8·1 answer
  • When you insert an object in a document, word always inserts it as a floating object. true or false.?
    11·1 answer
  • List the applications in the CyberOps menu.
    15·1 answer
  • What is co-operating process
    11·1 answer
  • Which best described most television in the 1940s and 1950s? color cable 24 hour black and white
    11·1 answer
  • No careers combine more than one value
    7·1 answer
  • Which of the following is a negative effect of the rise in agricultural technology following World War II?
    5·1 answer
  • Create a program to determine the largest and smallest number out of 15 numbers entered (numbers entered one at a time). This sh
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!