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
Today, the Nielsen Television Index provides weekly estimates of networks and major cable viewing audiences on a national level
Aleksandr-060686 [28]

Answer:

Audimeter

Explanation:

The television index is a measure of audience that estimates the percentage of households or viewers that are watching a television program and with respect to the total that your television is on during the broadcast. It manifests itself in a figure that results from the multiplication of individuals or households, by the time invested. This data is measured with audimeters.

6 0
3 years ago
Read 2 more answers
Which is a way that computer simulations of medicines could help reduce ethical issues in drug research? computer simulations co
Marat540 [252]
Computer simulations could reduce the need for testing on animals.
3 0
2 years ago
The answer for 1 and 2
Mrrafil [7]
1. A.  It is basically the definition of a political cartoon.
2. D. They used newspaper, protesting, and marches.
<span />
6 0
3 years ago
Given a string, convert the characters of the string into opposite case,i.e. if a character is lower case than convert it into u
o-na [289]

Answer:

// CPP program to Convert characters  

// of a string to opposite case  

#include<iostream>  

using namespace std;  

// Function to convert characters  

// of a string to opposite case  

void convertOpposite(string &str)  

{  

int ln = str.length();  

 

// Conversion according to ASCII values  

for (int i=0; i<ln; i++)  

{  

 if (str[i]>='a' && str[i]<='z')  

 //Convert lowercase to uppercase  

  str[i] = str[i] - 32;  

 else if(str[i]>='A' && str[i]<='Z')  

 //Convert uppercase to lowercase  

  str[i] = str[i] + 32;  

}  

}  

// Driver function  

int main()  

{  

string str = "GeEkSfOrGeEkS";  

 

// Calling the Function  

convertOpposite(str);  

 

cout << str;  

return 0;  

}  

Explanation:

8 0
3 years ago
A _______ is used to analyze and summarize your data without graphical support. A. PivotChart B. PivotTable C. chart D. table
Norma-Jean [14]
B. pivot table................................................
3 0
3 years ago
Other questions:
  • To create an individual version of a slide, you would click
    9·1 answer
  • __________ can be used to replace internal network addresses with one or more different addresses so the traffic that actually t
    9·1 answer
  • Explain why a document created by word processing software is stored as a binary file.​
    14·1 answer
  • The objective of an Enterprise Resource Planning (ERP) system is to create a customized software program that integrates the inf
    15·1 answer
  • What is the point of brainy when other people have to answer your questions but not the cumputer
    9·1 answer
  • What is computer system<br>explain the role of bank in computer<br>​
    15·2 answers
  • The function below takes two arguments: a string (name) and an integer (position). Complete the function so that it prints out t
    7·1 answer
  • What is the user requirements of an educational app
    15·1 answer
  • Which of the following is true about named ranges?
    6·1 answer
  • Often, a single source does not contain the data needed to draw a conclusion. It may be necessary to combine data from a variety
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!