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
abruzzese [7]
3 years ago
15

In JAVA, answer the following:

Computers and Technology
1 answer:
erica [24]3 years ago
7 0

Answer:

The JAVA program is as follows.

import java.util.Scanner;

public class Program

{

   static int n;

public static void main(String[] args) {

    //scanner object

    Scanner stdin = new Scanner(System.in);

    //loop executes till number entered is in the range of 1 to 10

    do

    {

        System.out.print("Enter any number: ");

        n = stdin.nextInt();

    }while(n<1 || n>10);

    System.out.println("Number is valid. Exiting...");

}

}

OUTPUT

Enter any number: 0

Enter any number: 23

Enter any number: 10

Number is valid. Exiting...

Explanation:

The program is explained.

1. The integer variable, n, is declared static since the variable should be accessible inside main() which is static.

2. An object of Scanner, stdin, is created inside main().

3. Inside do-while loop, the user is asked input any value for n.

4. The loop continues till user inputs a number which is not in the given range, beginning from 1 to 10.

5. The loop will not be terminated till the user enters a valid input.

6. Once a valid input is entered, the message is displayed to the console and the program ends.

7. The variable, n, is declared at the class level and is a class variable. Class variables are declared inside the class but outside all the methods in that class.

8. Since JAVA is a purely object-oriented language, all the code is written inside class.

9. The object of class is not created since only one class is included in the program. If more than one class is included, then the object of the class which does not has the main() method will be created inside main().

10. User input for integer is taken via scanner object and using nextInt() method.

11. The methods, print() and println() display the messages to the console. The only difference is that println() inserts a new line after displaying the message.

12. The name of the class having main() and the name of the program should be the same.

You might be interested in
In this program you will read in the number of seconds and convert it to days, hours, minutes and remaining seconds. Your progra
mart [117]

Answer:

// here is code in c++.

// include headers

#include <bits/stdc++.h>

using namespace std;

// main function

int main()

{

// variables

long long int inp_sec,days,hours,minutes,sec;

long long int s;

cout<<"please enter the seconds:";

 // read the input seconds

cin>>inp_sec;

 // make copy of input second

s=inp_sec;

 // compute days,86400 seconds in a day

days=inp_sec/86400;

 // update the seconds after counting days

inp_sec=inp_sec%86400;

 // compute hours, 3600 seconds in an hour

hours=inp_sec/3600;

 // update the seconds after counting hours

inp_sec=inp_sec%3600;

 //compute minutes, 60 seconds in a minute

minutes=inp_sec/60;

 // compute remaining seconds

sec=inp_sec%60;

 // print the output

cout<<s<<" seconds is equal to "<<days<<" days "<<hours<<" hours "<<minutes<<" minutes "<<sec<<" seconds "<<endl;

return 0;

}

Explanation:

Declare variables "inp_sec","days","hours","minutes" and "sec" of long long int type. read the seconds from user and assign it to variable "inp_sec".Make a copy of input  seconds.Then compute the days by dividing inp_sec with 86400 and update the inp_sec. then find hours by dividing inp_sec with 3600 and update the inp_sec.Similarly  find the minutes and remaining seconds.After this print the output.

Output:

please enter the seconds:83647362                                                                                                                            

83647362 seconds is equal to 968 days 3 hours 22 minutes 42 seconds

3 0
4 years ago
Calculate the total resistance of this simple circuit. If R1 = 100Ω, R2 = 200Ω.
andreyandreev [35.5K]

Answer: (66.7_1.8)Ω

Explanation: Hope it's helpful

3 0
2 years ago
Someone pleaseee answer my last question i just posted ;-;
USPshnik [31]
Lol sorry for wasting your time but I have to because it’s makin me answer questions
7 0
3 years ago
Read 2 more answers
Why do we need to measure the amperage of an electric current?​
Sonbull [250]

Answer:

Explanation:It is very important to have a way to measure and quantity the flow of electrical current. When current flow is controlled

It can be used to do useful work. The flow of current is measured in pampered. The term amps is often used for short.

5 0
3 years ago
In which country did the World Cyber Games originate?
levacccp [35]
The world cyber games originated in South Korea.
8 0
3 years ago
Read 2 more answers
Other questions:
  • Chris wants to guarantee that the instructions within the loop are executed one time regardless of thestatus of a condition. Whi
    9·1 answer
  • Bulldog Holdings is a U.S.-based consumer electronics company. It owns smaller firms in Japan and Taiwan where most of its cell
    5·1 answer
  • What typed of google group is best-suited for an online study group?
    7·1 answer
  • How would you convert an integer value to a float value in Python?
    10·1 answer
  • Which of these programmers creates the core game engine?
    5·2 answers
  • A local bank has just one branch. It sets up a peer-to-peer network for all devices on the system. The bank would like to be abl
    12·1 answer
  • What is the fundamental purpose of sentiment analysis on social media?​
    9·1 answer
  • FREEEEE 100 POINTS COME TAKE COME COME COME<br><br> only if u like da black panther
    8·2 answers
  • To meet the requirement for the number of vdss on board, what must be true about pyrotechnic vdss?
    15·1 answer
  • When a value of one data type is automatically changed to another data type, a(n) ____________________ type coercion is said to
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!