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
Dvinal [7]
2 years ago
12

Plz help me in this example

Computers and Technology
1 answer:
Gekata [30.6K]2 years ago
4 0

Answer:

import java.util.*;

public class calcarms

{

public static void main(String [] args)

{

 Scanner input = new Scanner(System.in);

 //Declare Variable

 int num;

 //Initialize num to 0

 num = 0;

 //Print heading

 System.out.println("Armstrong Numbers\t\tDifference between Successive Armstrong Numbers");

 //Call Armstrong method

 boolean result = Armstrong(num);  

}

public static boolean Armstrong(int num)

{

 int nums;

 //Initialize old_Arms and new_Arms to 0

 int old_Arms =0; int new_Arms = 0;

 for(int i = 0;i<=500;i++) //Iterate from 0 to 500

 {

  nums = i;

 int temp,calc = 0;

 temp = nums;  

  //Check individual digit of each number

 while(nums > 0)

 {

  int a=nums%10;  

  nums/=10;

  calc+=(a*a*a);//Find cube of number

 }

 if(temp == calc) //Check if number is armstrong

 {

  new_Arms = calc;

  old_Arms = new_Arms - old_Arms;

  System.out.println(calc+"\t\t\t"+old_Arms);//Print

  old_Arms = calc;      

 }

 }

 return true;  

};

}

Explanation:

Comments are used to explain difficult lines

You might be interested in
What does my name look like in binary code, btw my mane is Wendy Alexis Morales
jekas [21]
01010111 01100101 01101110 01100100 01111001 00100000 01000001 01101100 01100101 01111000 01101001 01110011 00100000 01001101 01101111 01110010 01100001 01101100 01100101 01110011
6 0
3 years ago
Read 2 more answers
One of your professors has asked you to write a program to grade her midterm exams, which consist of only 20 multiple-choice que
Lorico [155]

Answer:  

Here is the program that determines the number of questions that the student answered correctly.

#include <iostream>  //to use input output functions

#include <fstream>  // to handle files

#define size 20  //size of questions is fixed to 20

using namespace std;   //to identify objects cin cout

int correctAnswers(char answers[], char correct[]);  //to count correct answers given by student

   int main(){    //start of main function

       char correct[size];         // array stores correct answers

       char answers[size];       //stores answers of students

       int result;                     //stores the correct answers result of student

       double percentage;   //stores the percentage of correct answers

       int counter;        //counts number of correct answers given by student  

       ifstream reader("CorrectAnswers.txt");  //reads the contents of CorrectAnswers.txt file

       if(!reader){  //if file cannot be read/opened

           cout<<"Cannot open the file"<<endl; //displays error message

           return 0;        }          

       counter = 0;    //sets counter to 0 initially

       while( (reader>>correct[counter++]) && counter < size  );    //reads each answer from CorrectAnswers.txt  and stores it in char array correct[] at each iteration of while loop

       reader.close();  //closes the file

       reader.open("StudentAnswers.txt");    //opens StudentAnswers.txt file  

       if(!reader){   //if file could not be opened

           cout<<"Cannot open file"<<endl;   //displays this error message

           return 0;          }          

       counter = 0;    //sets counter to 0

       while( (reader>>answers[counter++]) && counter < size );   //reads each answer from StudentAnswers.txt  and stores it in char array answers[] at each iteration of while loop    

       result = correctAnswers(answers,correct);  //calls correctAnswers method to compute the correct answers given by student and stores the result of correct answers in result variable

       percentage = 100.0*result/size;   //computes percentage of correct answers of student    

       cout<<"The total number of questions answered correctly: "<<result<<endl;     //displays total no of qs answered correctly

       cout<<"The percentage of questions answered correctly: "<<percentage<<" %"<<endl;  //displays computed percentage

       if( percentage >= 75 ){  //if percentage of correctly answered questions is 75% or greater

           cout<<"Student has passed the exam!"<<endl;   } //displays that the student passed the exam

      else { //if percentage of correctly answered questions is below 75%

           cout<<"Student has failed the exam!"<<endl;         }  //displays that the student failed the exam

       return 0;     }  

   int correctAnswers(char answers[], char correct[]){   //method to compute the number of correct answers  

       int countCorrect = 0;   //stores the count of correct answers

       for(int i=0; i<size; i++){  //iterates 20 times to match answers from both the files of 20 questions

           if( answers[i] == correct[i] ){  // if the student answer in StudentAnswers.txt file matches with the correct answer given in CorrectAnswers.txt file

               countCorrect++;              }         }     //adds 1 to the countCorrect every time the student answer matches with the correct answer

       return countCorrect;     }  //returns the number of questions that the student answered correctly

Explanation:

The program is well explained in the comments mentioned with each line of code.

Here are the two files that can be used to check the working of the above program. You can create your own text files too.

     CorrectAnswers.txt :

A

A

B

D

C

C

A

C

D

D

A

B

A

B

B

C

A

C

C

B

StudentAnswers.txt

A

C

B

D

C

C

B

C

D

C

D

B

A

B

B

C

A

C

C

B      

Also if the number of wrong answers are to be displayed then add this method to the above code:

void wrongAnswers(char answers[], char correct[]){  //method takes two arrays one with correct answers and the other with student answers

       for(int i=0; i<size; i++){ //iterates 20 times

           if( answers[i] != correct[i] ){ //if the answer by student does not match with correct answer

               cout<<"Question Number: "<<i+1<<endl; //the question that is answered incorrectly

               cout<<"Correct answer is: "<<correct[i]<<endl;  //displays the correct answer

               cout<<"Student answer is: "<<answers[i]<<endl;    }    }    } //displays the answer that student gave

Now call this method in main() as:

if(result < size){  //if result is less than size i.e. 20

           cout<<"The questions answered incorrectly"<<endl;  //number of questions that are answered incorrectly

           wrongAnswers(answers,correct);  //calls method to compute the wrongly answered questions

       }else{  //if result is not less than size

           cout<<"No incorrect answers."<<endl;       }    //no questions incorrectly answered      

       cout<<"Number of missed questions: "<<size-result<<endl; //displays the number of missed questions

The screenshot of the output is attached.

8 0
3 years ago
What was Ada Lovelace's contribution to computer science?
Alika [10]

Answer:

She made the first computer.

Explanation:

Augusta Ada King, Countess of Lovelace (née Byron; 10 December 1815 – 27 November 1852) was an English mathematician and writer, chiefly known for her work on Charles Babbage 's proposed mechanical general-purpose computer, the Analytical Engine.

8 0
2 years ago
Read 2 more answers
Joshua wants to be a lawyer. He found the following table on the Bureau of Labor Statistics’ website to find out about the emplo
mars1129 [50]

The answer to your question is,

C) The number of lawyers will increase, so it may be difficult to find a job.

-Mabel <3

3 0
3 years ago
Read 2 more answers
Give state diagrams of DFAs that recognize the following languages.
k0ka [10]

Answer:

Following is attached the solution of each part step-by-step. I hope it will help you!

Explanation:

6 0
3 years ago
Other questions:
  • Write a program that loops one thousand times. add all the even numbers and display the results. add all the odd numbers and dis
    13·1 answer
  • What is the seventh byte in the roller coasters file?
    12·1 answer
  • Write an application named EnterUppercaseLetters that asks the user to type an uppercase letter from the keyboard. If the charac
    5·1 answer
  • When a bank account pays compound interest, it pays interest not only on the principal amount that was deposited into the accoun
    15·1 answer
  • What happens if an email server cannot find a matching username or the mailbox is full
    14·2 answers
  • Look for at least ten materials tools or anything you see at home (tle)
    14·1 answer
  • NEED ANS ASAP THANK YOU
    14·1 answer
  • What is another term used for next generation firewalls
    12·1 answer
  • Which statement best describes the computers all around us?
    15·1 answer
  • Complete the sentence.
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!