Write a java program with the following instruction:- class name: prime, instance variable: int n. Member methods:-
prime(): default constructor to initialize n
void input(int x): to assign n with x,
void display(): to check whether the number is prime or not

Answers

Answer 1

class Prime {

int num = 1;

boolean flag = false;

public void input(int x) {

this.num = x;

}

public void display() {

for (int i = 2; i <= num / 2; ++i) {

// condition for nonprime number

if (num % i == 0) {

flag = true;

break;

}

}

if (!flag)

System.out.println(num + " is a prime number.");

else

System.out.println(num + " is not a prime number.");

}

}

May be some bugs as it is an untested code written using a mobile phone


Related Questions

60 POINTS
IN JAVA

In this exercise, you will need to write a program that asks the user to enter different positive numbers.

After each number is entered, print out which number is the maximum and which number is the minimum of the numbers they have entered so far.

Stop asking for numbers when the user enters -1.

Possible output:

Enter a number (-1 to quit):
100
Smallest # so far: 100
Largest # so far: 100
Enter a number (-1 to quit):
4
Smallest # so far: 4
Largest # so far: 100
Enter a number (-1 to quit):
25
Smallest # so far: 4
Largest # so far: 100
Enter a number (-1 to quit):
1
Smallest # so far: 1
Largest # so far: 100
Enter a number (-1 to quit):
200
Smallest # so far: 1
Largest # so far: 200
Enter a number (-1 to quit):
-1

Answers

import java.util.Scanner;

public class JavaApplication75 {

   

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);

       int num = -2, largest = -1, smallest = -1;

       while (true){

           System.out.println("Enter a number (-1 to quit):");

           num = scan.nextInt();

           while (num < 0){

               if (num == -1){

                   System.exit(0);

               }

               num = scan.nextInt();

           }

           if (num > largest){

               largest = num;

           }

           if (num < smallest || smallest == -1){

               smallest = num;

           }

           System.out.println("Smallest # so far: "+smallest);

           System.out.println("Largest # so far: "+largest);

           

       }

   }

   

}

I hope this helps!

"If possible, always bring print-outs of your slides for your audience
members." Is this good advice?
A. If you can, this is always recommended, unless you are assured
everyone will have a tablet and you can share the files online.
B. No, this is not good advice since handouts rarely help the
audience in any manner. The only thing that matters is what the
speaker says.
C. Not really, since it is a lot of work, requiring a lot of paper, and
most people will not need the handouts.
D. Not really, because audience members will never need to review
slide information.

Answers

Answer:

Answer is A I just take the quiz.

Unless you are certain that everyone will have a tablet and can share the files online, it is always suggested to carry the print-out files of the slides.

Why it is important to bring the print-out files of the slides?

When the slides have a lot of component part, it's a good thought to overlap the copies of the presentation. A presentation is a misfortune medium for communicating ecumenical information.

If the audience has print-out files of the slides, they will be more focused on the themes that want to express rather than recalling every detail.

Unless a person knowing for sure that everyone will have a tablet and will be able to share the files online, it is always a good idea to have the print-out files of the slides with you.

Therefore, option A is correct.

Learn more about the audience, refer to:

https://brainly.com/question/1802560

#SPJ2

(On Python/ Edhesive) Test if a date is a payday based on the day of the month (15th or the 30th).

Sample Run
Enter today's day numerically: 17
Sorry, not a payday.
Enter today's day numerically: 30
It's payday!

Answers

Answer:

day = input("Enter today's day numerically: ")

if "15" in day or "30" in day:

print("It's payday!")

else:

print("Sorry, not a payday.")

Explanation:

Ask the user what day it is and store it in a variable called, day. Write a simple if else statement to check if ut is payday or not. This program can be more advanced by having payday be a variable.

Hackers crack hash functions by finding collisions or pre-generating millions of hashes and comparing them until find the one generated it.

A. True
B. False

Answers

Answer:

A. True

Explanation:

Most of the attacks on hash functions are based on finding collisions (so 2 different plain texts will match the same hash) or pre-generating millions of hashes and comparing them until you find the plain that generated it.

If a hash algorithm is reverse-engineerable or can be attacked that way, it's not a good hash algorithm.

What is pollution?
the introduction of harmful substances into the environment
the removal of waste from landfills and other waste collection areas
the addition of organic materials in order to clean dirty air and water
the combination of specific chemicals to decompose garbage

Answers

Answer:

other guy is correct it is A.

Explanation:

Did the quiz and got 100%. Edge 2021

The term pollution is the the introduction of harmful substances into the environment.

What is pollution?

Pollution is known to be the bringing in of contaminants into any natural environment that may lead to adverse change.

Therefore we can say that The term pollution is the the introduction of harmful substances into the environment and thus it is correct.

Learn more about pollution from

https://brainly.com/question/18657523

#SPJ2

Miranda is using Python 3 as a calculator and wants to divide 1374 by 3. What should Miranda type?
A.
print (1372 divided by 3)

B.
print (1374 )_ 3))

C.
print (1374 / 3)

D.
print (1372 ./. 3)

Answers

Answer:

C

Explanation:

Answer:

C

Explanation:

I got it right on a test.

An expert system used on a medical website accepts an input illness from the user and produces a list of possible symptoms. What type of function is the interface engine performing?
A.
backward chaining
B.
production unit
C.
production rule
D.
forward chaining
E.
knowledge base

Answers

The answer is froward chaining

Answer:

The correct answer would be:

D.

forward chaining

#PLATOFAM

Have a nice day!

What programs do coders use in businesses?

Answers

Answer:

The answer to this question is given below in the explanation section.

Explanation:

Software developers or coders use different programs to develop the program. The coders can use different programs in businesses and for businesses.

When a coder develops a program for business. They use different programming software for android, desktop, and web application development. They use different editors, database tools, testing tools, and browsers, etc.  These programs use different programming languages to develop business software such as:

JavaScriptSQLPythonC++ C# Ruby on RailsPHPBootstrapHTML and CSS etc.

 

PLEASE HELP
Which option is the correct format of placing HTML tags while coding in HTML?
A.
B.
C.
D.

Answers

Answer:

the 3rd one you put

Explanation:

Why don't jumbo jets have propellers?

Answers

Answer:

they are to heavy for tiny propellers to make fly

Explanation:

PLEASE HURRY!!!
Look at the image below

Answers

The output will be 18.

numA = 3 and everytime the for loop iterates, the value of the count variable is added to numA.

3 + 4 = 7

7 + 5 = 12

12 + 6 = 18

whats is mean by voice output devices

Answers

Answer:
Voice output communication aids (VOCAs), also called speech-generating devices (SGDs), are high-tech, augmentative, and alternative communication (AAC) devices that produce speech for an individual who has limited or no means to communicate orally. ... Different algorithms are used to create synthesized speech.

Which icon indicates that a layer is protected?
The Lock icon
The Shield icon
0 The Key icon
19
The Eye icon

Answers

Answer:

The lock icon.

Explanation:

A padlock icon, or lock icon, displayed in a web browser indicates a secure mode where communications between browser and web server are encrypted.

Lighting matters less in landscapes than in other types of photographs.
A.
True
B.
False

Answers

Answer:

A

Explanation:

that is the correct ans

How did the printing press make people more intelligent

Answers

Answer:

no

Explanation:

Answer:

the invention of the mechanical movable type printing press helped disseminate knowledge wider and faster than ever before.

a surface
A wooden block of weight 12 N kept on a table having
area of 4m² Calculate the pressure exerted on the table.​

Answers

Answer:

3 Pa

Explanation:

pressure = force / area

Which of the following describes the purpose of project management? planning and organizing resources to meet a goal arranging the order of tasks in a project presenting data in an organized manner producing a quality project

Answers

Answer:

The answer to this question is given below in the explanation section.

Explanation:

The question is about selecting the option among given options that best describes the purpose of project management.

The correct option of this question is the purpose of project management is planning and organizing resources to meet a goal.

Because project management is all about planning and organizing resources of a project to meet project goals.

Other options are not correct,

because arranging the order of tasks in a project, presenting data in an organized manner, and producing a quality project- all come under project management- are parts of planning and organizing steps of project management.

The answer is:

Planning and organizing resources to meet a goal

Read the following scenario, and then answer the question.
A family is ready to buy a new computer to replace their 8-year-old machine. The old computer was a Macintosh, and they would like another. They don’t play many games or movies on the machine, but need access to the Internet.

Which is the most important feature of a new computer for this family?
monitor size
operating system
memory
processing speed

Answers

Answer:

Monitor size

Explanation:

Hope this helps

Switching between slide sorter, reading, normal view helps you review your presentation, assess whether the slides have an attractive design and adequate content and make sure they are organized for the most impact.
True
False

Answers

Explanation: TRUE I TOOK THE TEST

What is 7/12 simplified?

Answers

Answer:

7 12

Explanation:

list all the components of a computer

Answers

Answer:

Motherboard, Central Processing Unit, Memory, Storage, Case, Fans, and Power supply.

Motherboard, Computer Memory, Central Processing Unit, Power Supply Unit, Graphics Processing Unit, Power Supply, USB Ports, Hard Drive, Floppy Drive, CD-ROM Drive, CD-RW Drive, DVD-ROM Drive, Keyboard, Video Card, Sound Card, Speaker, CPU Fan, Touchpad, Network Cards NIC

I’m sorry if I repeated any or left any out. So much stuff goes into making a computer but I hope this helped!

For hashing to work, it requires that

A. it must be easy to compute the output for any input.
B. it must be hard to compute the input for any output
C. both of the above
D. none of the above

Answers

Answer:

C. Both of the above

Explanation:

A. because the a main purpose of hashing is to store a lot of information in a string of random letters

B. because it is a form of encryption, though not absolutely impossible to break. That's also why it was worded as: it must be hard to...

Hi, can someone please help me with this? I've been having a lot of trouble with it.

The assignment

Your job in this assignment is to write a program that takes a message as a string and reduces the number of characters it uses in two different set ways. The first thing your program will do is ask the user to type a message which will be stored as a String. The String entered should be immediately converted to lowercase as this will make processing much easier. You will then apply two different algorithms to shorten the data contained within the String.

Algorithm 1

This algorithm creates a string from the message in which every vowel (a, e, i, o, and u) is removed unless the vowel is at the very start of a word (i.e., it is preceded by a space or is the first letter of the message). Every repeated non-vowel character is also removed from the new string (i.e., if a character appears several times in a row it should only appear once at that location). So for example the string "I will arrive in Mississippi really soon" becomes "i wl arv in mssp rly sn".

After applying this algorithm, your program should output the shortened message, the number of vowels removed, the number of repeated non-vowel characters removed, and how much shorter the shortened message is than the original message. The exact format in which the program should print this information is shown in the sample runs.

Algorithm 2

This algorithm creates a string by taking each unique character in the message in the order they first appear and putting that letter and the number of times it appears in the original message into the shortened string. Your algorithm should ignore any spaces in the message, and any characters which it has already put into the shortened string. For example, the string "I will arrive in Mississippi really soon" becomes "8i1w4l2a3r1v2e2n1m5s2p1y2o".

After applying this algorithm, your program should output the shortened message, the number of different characters appearing, and how much shorter the shortened message is than the original message. The exact format in which the program should print this information is shown in the sample runs.

Sample Run 1
Type the message to be shortened
This message could be a little shorter

Algorithm 1
Vowels removed: 11
Repeats removed: 2
Algorithm 1 message: ths msg cld b a ltl shrtr
Algorithm 1 characters saved: 13

Algorithm 2
Unique characters found: 15
Algorithm 2 message: 4t2h2i4s1m5e2a1g1c2o1u3l1d1b2r
Algorithm 2 characters saved: 8
Sample Run 2
Type the message to be shortened
I will arrive in Mississippi really soon

Algorithm 1
Vowels removed: 11
Repeats removed: 6
Algorithm 1 message: i wl arv in mssp rly sn
Algorithm 1 characters saved: 17

Algorithm 2
Unique characters found: 13
Algorithm 2 message: 8i1w4l2a3r1v2e2n1m5s2p1y2o
Algorithm 2 characters saved: 14
Milestones
As you work on this assignment, you can use the milestones below to inform your development process:

Milestone 1: Set up a program that takes a string input and converts all the letters to lowercase. Start implementing algorithm 1: create a counter variable and iterate through the characters of the String, incrementing this each time a vowel is encountered which is not preceded by a space or is at the start of the String. So at the end of the loop this counts the number of vowels that are not at the start of a word.

Milestone 2: Add further conditions (using else if) in your loop to count any non-vowel characters which appear immediately after the same character. Make a new empty String to hold the shortened message at the start of the code, then add a final else condition in the loop to add all characters which were not vowels or repeated letters to this String. Then print the statements for algorithm 1 using your counts and shortened message.

Milestone 3: Start implementing algorithm 2 by writing code that iterates through the String and checks that each character is not a space and has not already appeared in the word before that point. You will need to use nested loops - an outer loop to iterate through the String characters and an inner loop that looks through the previous characters up to that point - and a flag variable to record if a letter was found in the inner loop. Use a counter variable to count all such "unique" characters in the String.

Milestone 4: Add a second inner loop inside the outer loop from the previous which counts all appearances of a character that passes the tests from milestone 3. Add the character and the number of times it appears to another shortened message String (which should start as blank String). Finally, print the statements for algorithm 2 using your unique character count and shortened message.

Answers

Answer:

Scanner scan = new Scanner(System.in);

System.out.println("Type the message to be shortened");

String msg = scan.nextLine();

System.out.println();

msg = msg.toLowerCase();

String newStr = "";

System.out.println("Algorithm 1");

int vowels = 0;

int repeats = 0;

for(int i = 0; i < msg.length(); i++)

{

if((msg.substring(i, i +1).equals("a") || msg.substring(i, i+1).equals("e") || msg.substring(i, i +1).equals("i") || msg.substring(i, i+1).equals("o") || msg.substring(i, i +1).equals("u")))

{

if(i != 0 && !msg.substring(i -1, i).equals(" "))

{

vowels++;

}

else

newStr += msg.substring(i, i +1);

}

else if(i != 0 && msg.substring(i, i +1).equals(msg.substring(i -1, i)))

{

repeats++;

}

else

{

newStr += msg.substring(i, i +1);

}

}

System.out.println("\nAlgorithm 1");

System.out.println("Vowels removed: " + vowels);

System.out.println("Repeats removed: " + repeats);

System.out.println("Algorithm 1 message: " + newStr);

System.out.println("Algorithm 1 characters saved: " + (vowels + repeats));

algorithm2(msg);

}

public static void algorithm2(String msg)

{

String alg2Msg = "";

int uniqueLetters = 0;

// Iterate through each letter in msg

for(int i=0; i < msg.length(); i++)

{

String ltr = msg.substring(i,i+1);

// Only process if this character is not a space

if(!ltr.equals(" "))

{

/* Check whether this character has already appeared by

* iterating through characters from start up to the current

* letter and using a boolean flag variable.

*/

boolean alreadyUsed = false;

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

{

if(msg.substring(j,j+1).equals(ltr))

{

alreadyUsed = true;

}

}

/* If this character hasn't already appeared,

* iterate through the rest of the characters

* and count how many times it appears.

*/

if(!alreadyUsed)

{

uniqueLetters++;

int count = 0;

for(int j=i; j<msg.length(); j++)

{

if(msg.substring(j,j+1).equals(ltr))

{

count++;

}

}

alg2Msg += count + ltr;

}

}

} //end for loop

System.out.println("\nAlgorithm 2");

System.out.println("Unique characters found: " + uniqueLetters);

System.out.println("Algorithm 2 message: " + alg2Msg);

System.out.println("Algorithm 2 characters saved: " + (msg.length() - alg2Msg.length()));

} //end algorithm2

}

Explanation:

Here you go!

What is the text output by the program?


A. Less than 10
B. Less than 20
C. Less than 30
D. 30 or more

Answers

Answer:

30 or more

Explanation:

30 or more is the answer

Thanks hope that helps my dude

4. Assume you have a list of numbers
12,10,32,3,66,17,42,99,20
a) Write a loop that prints each of the numbers on a new line.
b) Write a loop that prints each number and its square on a new line.

Answers

lst = [12,10,32,3,66,17,42,99,20]

a)

for x in lst:

   print(x)

b)

for x in lst:

   print(str(x) + " " +str(x**2))

I think this is what you're looking for. Hope this helps!

HELLLLPPPPPP Jerry needs to move his Turtle forward 25 pixels. Which line of code should Jerry use?

tom(25)
tom.forward(25)
tom.turtle(25)
tom.right(twenty-five)

Answers

If your turtle is defined and you named the variable tom, the code would be:

tom.forward(25)

Jerry should use the line of code tom.forward(25) to move his Turtle forward 25 pixels. The correct option is 2.

What is coding?

The process of designing, writing, testing, and maintaining the source code of software programmes, websites, and other computer applications is referred to as coding.

Because the forward() method is used to move the turtle forward by a specified number of pixels or units, the line of code tom.forward(25) should be used to move the turtle forward by 25 pixels.

The turtle object is named Tom in this case, and the method forward() is called on it with the argument 25, indicating that the turtle should move forward 25 pixels.

Thus, the correct option is 2.

For more details regarding coding, visit:

https://brainly.com/question/17204194

#SPJ2

What is the error in this?

userGuess = int(input(“Guess a number between 1 and 20: “))

Answers

Most interpreters won't recognize “ “as a quote. You need to use " ". Other than that, your code looks good.

What other jobs would require employees to follow directions very carefully? (Give 4 examples)​

Answers

construction, surgeon, army, teachers

You are looking at computer ads. One has a processor that is 3.64GHz. What does this mean?

It can download 3.64 gigabits per second.

It can convert binary to decimal at the rate of 3.64 trillion numbers per second.

It can upload 3.64 gigabits per second.

It can execute 3.64 billion instructions per second.

Answers

Answer:

The higher the clockspeed the more the cpu can do

Explanation:

The distance between two walls is called what?

Answers

Answer:

The Nikuradze mixing-length

Explanation:

Awnser: Mixing length
Other Questions
Briefly tell about one treatment option for depression A net force of 34 N is applied to accelerate an object at a rate of 2.5 m/s. What is the mass of the object? Q.28 :-Tap A can fill a tank in 60 minutes while tank B can fill it in 90 minute. The opening at the bottom can empty the full tank in 3 hours. When thetank was empty both the taps were opened to fill the tank. After 15 minutes it was detected that the opening at the bottom was left unblocked andimmediately it was closed. After how much more time was the tank completely filled ?24 minutes27 minutes21 minutes30 minutes Question 1 of 5Which two ratios represent quantities that are proportional?A. 56/64 and 36/48 B 21/28and 12/16 C. 9/10and 10/9 D. 5/7 and 7/14 Which statement is the lie?Part A: Prompt: \large 4n-3A. Three less than four times a numberB. Four times a number less than 3C. Four times a number decreased by 3 select the appropriate linear model for the scatter plot Listen to the audio and then answer the following question. Feel free to listen to the audio as many times as necessary before answering the question. What was recently opened in the downtown area? - la estacin de policia - el centro comerial un museo y una biblioteca - la farmacia *** un museo y una biblioteca*** Brittany found a skirt on sale.The price tag says $38 with25% off. How much will shepay for the skirt? A teacher grades 27 tests in 3 hours How many tests can the teacher grade in 8 hours if he works at the same rate Question 22 (2 points) What is one outcome of Mestrals invention in Natural Inspiration that is not shared by the scientists invention in A Brilliant Beetle?Question 22 options:Mestrals invention has proved to be financially successful.Mestrals invention is able to replenish something found in nature.Mestrals invention can be used to solve more than one problem.Mestrals invention inspired new uses beyond its original purpose I need it to be in least to greatest ANSWER QUICKLY..It is your birthday and you are going to get a new cell phone. The dayyou buy the phone, you will have to pay the $59 interest fee and a $250down payment. The remaining balance of the phone will be paid off in 24equal payment. The total bill is $909, including the interest fee and downpayment. What will be the cost of your monthly payments for the newcellphone?50 payments42 payments25 payments30 payments The average atomic mass of potassium is 39.098 amu. This element has 3 naturally occurring isotopes K-39, K-40, and K-41. Which is likely to be most abundant? plz help and plz with an explination don't make fun of me bc I just put random answers I NEED HELP ASAP!!PLEASE HELP ME WITH MY MATH! Evaluate the following expression. -7 x (7 + 9) A _________ surrounds every contient fill in the blank for brainiest:) The slope of a line can be stated many ways if not put into simplest form.True/False: 2is one way to correctly state the slope of the line shown.TrueFalse Which star reaches a greater apparent brightness? THIRTY POINTS!What are important themes in "Garden of Mu Childhood"? Select all that apply!VictimizationFriendshipIndividualismViolence