Question

What is the java code for this.The goal of this lab is to write two programs, Summation and Prime, that execute simple tasks. The first computes the summatiPrime Note that an integer > 2 is prime if no integer between 2 and itself completely divides it. An integer > 2 is composite

0 0
Add a comment Improve this question Transcribed image text
Answer #1
SOURCE CODE:-

*Please follow the comments to better understand the code.
**Please look at the Screenshot below and use this code to copy-paste.
***The code in the below screenshot is neatly indented for better understanding.

Please give me an upvote dear, Much Appreciated.!!




import java.util.Scanner;

public class Summation
{
    public static void main(String[] args) {
        System.out.print("Enter start end and gap: ");
        Scanner scanner=new Scanner(System.in);
        // read the data
        int start=scanner.nextInt();
        int end=scanner.nextInt();
        int gap=scanner.nextInt();

        // print the numbers and calculate sum
        if(start>end)
        {
            // swap
            int temp=start;
            start=end;
            end=temp;
        }
        int sum=0;
        for(int i=start;i<=end;i+=gap) {
            System.out.print(i + " ");
            sum+=i;
        }
        // print the sum
        System.out.println("\nThe total is "+sum);

    }
}

=====

import java.util.Scanner; 1 Lluje 3 public class Summation 5 public static void main(String[] args) { System.out.print(Enter


Please note that in the given time, it is not possible to solve both the questions.
Please post the second one as another question.

If there are any doubts, comment down here. We are right here to help you. Happy Learning..!! PLEASE give an UPVOTE I Have Pu

Add a comment
Know the answer?
Add Answer to:
What is the java code for this. The goal of this lab is to write two...
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
  • All code will be in Java, and there will be TWO source code. I. Write the...

    All code will be in Java, and there will be TWO source code. I. Write the class  MailOrder to provide the following functions: At this point of the class, since we have not gone through object-oriented programming and method calling in detail yet, the basic requirement in this homework is process-oriented programming with all the code inside method processOrderof this class. Inside method processOrder, we still follow the principles of structured programming.   Set up one one-dimensional array for each field: product...

  • Java Write a Simple Program This question is about following the directions below. Failure to do...

    Java Write a Simple Program This question is about following the directions below. Failure to do so, results in lost credit. Write the definition of a method that takes in an integer number, and returns true if the number is prime, otherwise, returns false. A prime number is only divisible by itself and 1. Do not write the code for main here. The code must follow these steps in the order shown: 1. Name the method isPrime, and make it...

  • • Next to these lines, write functional Java codes that will: (1) ask user to input...

    • Next to these lines, write functional Java codes that will: (1) ask user to input a positive integer, such as 15; (2) create a void type of method named "findSum" that takes a parameter of int type named "n". Make sure the "findSum" method can calculate the sum of 1+2+3+ ... +n; and (3) use the "System.out.println(" to display the newly calculated sum. The following is a sample output: Enter an integer: 15 120 Enter an integer: 10 Enetr...

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods...

    CIST 2371 Introduction to Java Unit 03 Lab Due Date: ________ Part 1 – Using methods Create a folder called Unit03 and put all your source files in this folder. Write a program named Unit03Prog1.java. This program will contain a main() method and a method called printChars() that has the following header: public static void printChars(char c1, char c2) The printChars() method will print out on the console all the characters between c1 and c2 inclusive. It will print 10...

  • The following code is a Java code for insertion sort. I would like this code to...

    The following code is a Java code for insertion sort. I would like this code to be modified by not allowing more than 10 numbers of integer elements (if the user enters 11 or a higher number, an error should appear) and also finding the range of the elements after sorting. /* * Java Program to Implement Insertion Sort */ import java.util.Scanner; /* Class InsertionSort */ public class InsertionSortTwo { /* Insertion Sort function */ public static void sort( int...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • WHILE LOOPS (13 points) Write a MATLAB program to find the smallest integer N such that:...

    WHILE LOOPS (13 points) Write a MATLAB program to find the smallest integer N such that: i> limit For example, if the limit is 5, the smallest N would be 3 since 1 + 2 + 3 = 6, and 6 > 5. If the limit is 15, the smallest N is 6 because 1+ 2+ 3+ 4+ 5+ 6 = 21. Note that N is not 5 in this case because 1+ 2+ 3+ 4+ 5 = 15, and...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If 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