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...

  • Homework Case 1 Statistics - Please explain and show how to create graphs and charts. Pelican Stores a division of National Clothing, is a chain of women's apparel store operating throughout the c...

    Homework Case 1 Statistics - Please explain and show how to create graphs and charts. Pelican Stores a division of National Clothing, is a chain of women's apparel store operating throughout the country.The chain recently ran a promotion in which discount coupons were sent to customers of othe National Clothing stores. Data collected for a sample of 100 in-store credit card transactions at Pelican Stores during one day while the promotion was running are contained in the file name Pelican...

  • 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,...

  • 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...

  • 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...

  • Article Summary I Read the article below and provide feedback by writing a 2 page summary....

    Article Summary I Read the article below and provide feedback by writing a 2 page summary. Please write in essay format (you may include the questions but the response should be in essay format) Must include the following information Title of the article Author(s) of the article Reference list (include the article itself and any other reference material such as another article that is cited in your summary). Use the reference list in the article to get information about another...

  • 1) What are the two hypotheses of this experiment? What are you predictions for each hypotheses...

    1) What are the two hypotheses of this experiment? What are you predictions for each hypotheses & briefly describe how you will test the given hypothesis and the one you generated. 2) What is a histogram AND why is it used for this lab instead of just plotting each individual's data? 3) Does the multi-year TRC (total ridge count) support each hypothesis? (explain your answer in terms of the shape and the position of the curve.) 4) What might account...

  • Hello! Could you please write your own four paragraph (5-6 sentences per paragraph) take away or...

    Hello! Could you please write your own four paragraph (5-6 sentences per paragraph) take away or reflection of the below information? Please complete in 24 hours if possible. Thank you! RIS BOHNET THINKS firms are wasting their money on diversity training. The problem is, most programs just don’t work. Rather than run more workshops or try to eradicate the biases that cause discrimination, she says, companies need to redesign their processes to prevent biased choices in the first place. Bohnet...

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