Question

Concepts tested by this program: Variables Input/output .Loops Conditional Statements Methods . Arrays . Multi-Dimensional Ar

Program 2: (Pattern Recognition)Consecutive four equal numbers Problem Description: Write the following function that tests w

JAVA PLEASE

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

I don't know how to solve problem 2 But I do know about Problem 1

Below is the JAVA code I hope that i have provided sufficient comments for your better understanding Note that I have done proper indentation but this code is automatically left alligned on this interface

public class Locker{

public static void main(String []args)
{
boolean[] arr = new boolean[101]; //Initialized by false (default)
int i,j;
for( i=1;i<=100;i++) //i represents student number
{
for( j=i;j<=100;j+=i) //j represents the locker number
{
if(arr[j]==false) //If locker is closed than open it
arr[j]=true;
else //else close it
arr[j]=false;
}
}
System.out.print("Open lockers are: ");
for( j=1;j<=100;j++)
{
if(arr[j]==true) //This locker is open
System.out.println("Locker "+j+" is open");
}
}
}

Below is the screenshot of output

G:1Javaljdk1.8.e_111\binljava programs javac Locker.java G:1Javaljdk1.8.e_111\binljava programs java Locker Open lockers are:

I have tried to explain it in very simple language and I hope that i have answered your question satisfactorily.Leave doubts in comment section if any.

Add a comment
Know the answer?
Add Answer to:
JAVA PLEASE Concepts tested by this program: Variables Input/output .Loops Conditional Statements Methods . Arrays ....
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
  • I need help writing a program for this assignment Problem: Locker puzzle A school has 100...

    I need help writing a program for this assignment Problem: Locker puzzle A school has 100 lockers and 100 students. All lockers are locked on the first day of school. As the students enter, the 1st student opens every locker. Then the 2nd student, begins with the 2nd locker, closes every other locker. The 3rd student begins with the 3rd locker and changes every 3rd locker (closes it if it's open and opens it if its closed). The 4th student...

  • The Lockers Problem There is a well-known mathematical logic problem called the lockers problem. Here is...

    The Lockers Problem There is a well-known mathematical logic problem called the lockers problem. Here is a description of the problem 23 24 25 26 A new high school has just opened! There are 50 lockers in the school and they have been numbered from 1 through 50. When the school opens the first student to enter the school walks into the hallway and opens all the locker doors! Afterwards, the second student closes each door whose number is a...

  • C++ Arrays & Methods

     #2: Design and implement a program (name it CompareArrays) that compares the content of 2 single-dimensional arrays of the same size. The program prompts the users to enter the array size. Then prompts the user to initialize each array with integer values. The program defines method Compare() that takes two signal-dimensional arrays of type integer. The method compares the content of the arrays and returns true (Boolean type) if the arrays store same values in the same order. Otherwise, it...

  • C++ Single Dimensional Arrays

    Exercise #1: Design and implement a program (name it AssignGrades) that stores and processes numeric scores for a class. The program prompts the users to enter the class size (number of students) to create a single-dimensional array of that size to store the scores. The program prompts the user to enter a valid integer score (between 0 and 100) for each student. The program validates entered scores, rejects invalid scores, and stores only valid scores in the array.  The program...

  • Concepts tested by the program: Working with one dimensional parallel arrays Use of functions Use of...

    Concepts tested by the program: Working with one dimensional parallel arrays Use of functions Use of loops and conditional statements Description The Lo Shu Magic Square is a grid with 3 rows and 3 columns shown below. The Lo Shu Magic Square has the following properties: The grid contains the numbers 1 – 9 exactly The sum of each row, each column and each diagonal all add up to the same number. s is shown below: Write a program that...

  • You are asked to build and test the following system using Java and the object-oriented concepts ...

    You are asked to build and test the following system using Java and the object-oriented concepts you learned in this course: Project (20 marks) CIT College of Information technology has students, faculty, courses and departments. You are asked to create a program to manage all these information's. Create a class CIT to represents the following: Array of Students, each student is represented by class Student. Array of Faculty, each faculty is represented by class Faculty. Array of Course, each course...

  • Write a C++ program that asks user number of students in a class and their names....

    Write a C++ program that asks user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’ names and ranking. Follow the Steps Below Save the project as A4_StudentRanking_yourname....

  • Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges...

    Assignment 6, Merge Arrays (java) Instructions In this assignment, you will write a program which merges two arrays of positive integers and removes any duplicate entries. Your program will first ask for a valid length which must be an integer which is 10 or greater. The program should continue to ask until a valid length is entered. The program will then create two arrays of the length entered, fill these with random integers between 1 and 100 inclusive, and print...

  • CSCI 111 Assignment 4 Aim: To write some programs using loops, arrays and library functions. Procedure:...

    CSCI 111 Assignment 4 Aim: To write some programs using loops, arrays and library functions. Procedure: Part A: Consider an apartment block which has 40 units. The letterboxes for the 40 units are lined up in sequence outside the building, and are numbered 1 to 40. We're going to play with the boxes. Start with all the boxes closed. Next, starting with box 2, open every alternate box (that is, 2, 4, 6, ...). Next, starting with box 3, change...

  • Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a...

    Kindly solve this using C PROGRAMMING ONLY. 4. Write a program marks.c which consists of a main function and three other functions called. readmarks , changemarks (, and writemarks() The program begins by calling the function readmarks () to read the input file marksin. txt which consists of a series of lines containing a student ID number (an integer) and a numeric mark (a float). Once the ID numbers and marks have been read into arrays (by readmarks () the...

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
ADVERTISEMENT