Question

All the programs are to be written in java 1. WAP to print American Flag Using...

All the programs are to be written in java

1. WAP  to print American Flag Using Loop in as minimum code as possible.

1.1 Ask user to enter age, sex ( M or F ), marital status ( Y or N ) and then using following rules print their place of service.
   if employee is female, then she will work only in urban areas.

   if employee is a male and age is in between 20 to 40 then he may work in anywhere

   if employee is male and age is in between 40 t0 60 then he will work in urban areas only.

   And any other input of age should print "ERROR".
  
  
1.2.    Write a program to print all prime number in between 1 to 100.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

American flag using simple loops:

class Main{
public static void main (String[] args) {
for(int i=0;i<3;i++){
System.out.println("*****=====");
}
for(int i=0;i<3;i++){
System.out.println("==========");
}
}
}
1. class Main{ public static void main(String[] args) { for(int i=0;i<3;i++){ System.out.println(*****=====); for(int i=0;i

Please upvote my answer.

Thank you.



1.1)

import java.util.*;
class Main{
public static void main (String[] args) {
int age;
char sex,m;
Scanner inp=new Scanner(System.in);
System.out.println("Enter age");//read inputs from user
age=inp.nextInt();
System.out.println("Enter sex");
sex=inp.next().charAt(0);
System.out.println("Enter Marital status");
m=inp.next().charAt(0);
if(sex=='F')
System.out.println("Urban Areas");//check conditions and print the place of service
else if(sex=='M' && age>=20 && age<=40)
System.out.println("Any place");
else if(sex=='M' && age>=40 && age<=60)
System.out.println("Urban Areas");
else
System.out.println("ERROR");
}
}

Enter age 25 Enter sex Enter Marital status Urban Areas ... Program finished with exit code o Press ENTER to exit console.
Please upvote my answer.

Thank you.

1.2)

class Main{
public static void main (String[] args) {
int c=0;
for(int i=1;i<=100;i++){//for numbers in range 1 to 100
c=0;
for(int j=i;j>=1;j--){//check for prime
if(i%j==0)
c++;//increment c if it is divisible
}
if(c==2){
System.out.println(i);//print number
}
}
}
}

Screenshot:


... Program finished with exit code o

Please upvote my answer.

Thank you.

Add a comment
Know the answer?
Add Answer to:
All the programs are to be written in java 1. WAP to print American Flag Using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ________________ ________________ ______________ 11. Using Excel - Scatter diagrams, estimated regression equations, and trendlines Suppose a...

    ________________ ________________ ______________ 11. Using Excel - Scatter diagrams, estimated regression equations, and trendlines Suppose a company records data on sales calls, induding the length of each call and whether a sale was made. The manager is interested in determining whether there is a relationship between the average time spent per call and the number of sales made by each employee, so she obtains the average call length and the total number of sales over a 2-week period for a...

  • 1)     Affirmative Action programs are typically designed to? Create homogeneous employment groups Be punitive Protect white,...

    1)     Affirmative Action programs are typically designed to? Create homogeneous employment groups Be punitive Protect white, non Hispanic Americans Rectify past discrimination 2)     Asa and Ruby both sell insurance. Asa is married, has three children, and a new house. Ruby is single and has recently purchased a new Lexus. According to the industrial psychologists ______________. How well their employer motivates them relates directly to their individual needs They will be motivated by the same needs Asa can be motivated through...

  • CASE 2.5 Cosmopolitan Magazine 373 CASE 2.5 cOSMOPOLITAN MAGAZINE Surveys are often sponsored and...

    CASE 2.5 Cosmopolitan Magazine 373 CASE 2.5 cOSMOPOLITAN MAGAZINE Surveys are often sponsored and conducted by various popular press outlets to spur interest among and create a more inreractive relationship with their readers. Nowadays, surveys asking people abour their consumer preferences, shopping behavior, general opi nions, even their sexual habits, are commonplace, but this was not always so. A land mark survey of this kind, often characterized as such due to its ens sample of 106,000, was conducted in 1980,...

  • 1.- Based on the below reading, using Critical Analysis, based on the concepts of text, comment,...

    1.- Based on the below reading, using Critical Analysis, based on the concepts of text, comment, and answer What can we learn from the great business leaders? WHAT CAN WE LEARN FROM GREAT BUSINESS LEADERS? 2.- Depending on the below reading assigned, using Critical Analysis, based on the concepts of reading, comment on your optics regarding the last three paragraphs of the reading conclusions. WHAT CAN WE LEARN FROM THE BIG BUSINESS LEADERS? William Henry “Bill” Gates III was born...

  • Please read and answer the following questions. 1. How was the sample selected ? We’re demographics...

    Please read and answer the following questions. 1. How was the sample selected ? We’re demographics collected ? 2. Is the sample representative of the target population? If not how was the sample “improved “ to make the results more reliable and valid? 3. What is the design of the study? 4. How were the human subjects protected ? 5. Were instruments used reliable and valid ? Did they measure the phenomenon under the study( how do you know that...

  • Comprehensive Income Tax Course: Module 1 4. Randy turned 16 last year and had his first...

    Comprehensive Income Tax Course: Module 1 4. Randy turned 16 last year and had his first summer job. Even though his parents are claiming him as a dependent he wants to file a return in order to get his refund. He receives his W-2 and decides he can do his own return using form 1040-EZ. Which of the following information is not found on a Form W-2? a) The taxpayer’s Social Security number b) The taxpayer’s wages, tips and other...

  • ** Please read the case study below to answer question 1, 2 and 3 Starbuck Community....

    ** Please read the case study below to answer question 1, 2 and 3 Starbuck Community. Connection. Caring. Committed. Coffee. Five Cs that describe the essence of Starbucks Corporation, what it stands for and what it wants to be as a business. With more than 19,000 stores in 62 countries, Starbucks is the world's number one specialty coffee retailer. The company also owns Seattle's Best Coffee, Tsavana. Taze, Starbucks VIA, Starbucks Refreshers, Evolution Fresh, LaBoulange, and Verismo brands. It's a...

  • Hi, Kindly assist with my project management assignment below using the attached case study Question 1 Update the project charter for the remainder of the project in response to Adams’ memo (lines 241...

    Hi, Kindly assist with my project management assignment below using the attached case study Question 1 Update the project charter for the remainder of the project in response to Adams’ memo (lines 241 through 246). Question 2 Prepare a plan for the remainder of the project in response to Adams’ memo (lines 241 through 246). Your answers to the above will be assessed in terms of the level of communication displayed, the insights and inferences drawn, and your ability to...

  • All of the following questions are in relation to the following journal article which is available...

    All of the following questions are in relation to the following journal article which is available on Moodle: Parr CL, Magnus MC, Karlstad O, Holvik K, Lund-Blix NA, Jaugen M, et al. Vitamin A and D intake in pregnancy, infant supplementation and asthma development: the Norwegian Mother and Child Cohort. Am J Clin Nutr 2018:107:789-798 QUESTIONS: 1. State one hypothesis the author's proposed in the manuscript. 2. There is previous research that shows that adequate Vitamin A intake is required...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT