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
Explain the steps you take to complete an Internet search. Do you use a particular search engine every time or do you alternate?
Naddik [55]
1. Personally, I always use the same search engine, which is Google. I once opened Bing mistakenly, but obviously returned to Google immediately. Google is my preferred choice because I've used it for such a long time that I've gotten so used to it and cannot change it. The other search engines don't look as appealing to me as Google.

2. Some advantages would be definitely the format of the information you get from a search engine as opposed to the metasearch engine - sometimes, the metasearch engine cannot provide you with complete results or even complete sentences, so you may be left with illegible texts. On the other hand, metasearch engines can give you so much more information than regular search engines.

3. If the credentials seem legit, based on particular rules as to how to write sources used (such as Chicago style, APA, etc.), then you can safely assume the source is credible. If the author wrote everything necessary in his text (especially works cited/links available), you can usually trust that source.
5 0
3 years ago
The type of line shown below represents an / a:​
VikaD [51]

Answer:

esrfsrtg

Explanation:

6 0
3 years ago
Which protocol below is used by email clients to send email
Alex17521 [72]
Did you forget the picture?
6 0
3 years ago
In the ( ) Model, each in a network can act as a server for all the other computers sharing files and acsess to devices
Pavel [41]

Answer:

C peer to peer

Explanation:

  • A peer to peer is a computer network in a distributed architecture that performs various tasks and workload amount themselves. Peers are both suppliers and consumers of resources. Peers do similar things while sharing resources, which enables them to engages in greater tasks.
3 0
3 years ago
Write a program that lets the user enter a nonnegative integer then uses a loop to calculate the factorial of that number. Displ
ValentinkaMS [17]

Answer:

Following are the program in c++ language

#include <iostream> // header file

using namespace std;// namespace

int main() // main function

{

    int num; // variable declaration

    long int f=1; // variable declaration

   do

   {

       cout<<"Enter the Positive value:";

       cin>>num;

   } while(num<0); // i check whether   number is non negative or not

   while(num>0) // iterating over the loop

   {

       f=f*num; // calculate the factorial

       num--; // decrement the value of num by 1

   }

   cout<<" factorial is :"<<f; // display the factorial .

   return 0;

}

Output:

Enter the Positive value:7

factorial is :5040

Explanation:

Following are the description of the program .

  • Read the input by user in the "num" variable of "int" type..
  • The do-while will check the enter number is nonnegative number.  
  • While(n>0) loop is calculating the factorial in the  "f" variable .
  • Finally display the factorial .  
3 0
3 years ago
Other questions:
  • (PLS HELP 99 POINTS) In a paragraph of no less than 125 words, explain the three aspects involved in gaining a true appreciation
    14·2 answers
  • you are configuring a wireless connection on your home router. Because you live in an apartment complex, the level of security i
    5·1 answer
  • Identify ways you can manage a project using project management software
    14·1 answer
  • A call center company wants to implement a domain policy primarily for its shift workers. The call center has large groups with
    11·1 answer
  • Please answer questions 34, 36 &amp; 37. <br><br>No explanation required. ​
    8·1 answer
  • These statements describe a network server.
    5·1 answer
  • What are Manuscript signs​
    8·1 answer
  • What is a web server?​
    11·1 answer
  • How do you give brianliest
    13·1 answer
  • MULTI-SELECT
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!