Write a program to solve the following expression by taking user input s^5+c^2+q

Share Your Love

Hello guys, welcome to lingarajtechhub.com . Today we are going to discuss the following expression by taking user input s^5+c^2+q.

Code:

package com.sum_mul.java;
import java.util.Scanner;
public class SumMul {

	public static void main(String[] args) {
		int s,c,q;
		Scanner sc=new Scanner(System.in);
		System.out.println("Enter the value of s:");
		s=sc.nextInt();
		System.out.println("Enter the value of c:");
		c=sc.nextInt();
		System.out.println("Enter the value of q:");
		q=sc.nextInt();
             int z= (s*s*s*s*s)+(c*c)+q;
      System.out.println("Output of s^5+c^2+q is:\n"+z);
	}

}

Line-1:

  • package com.sum_mul.java

   It is a java package , this package is created in a java project and it contains classes inside  the package.

Line-2:

  • import java.util.Scanner

In java, Scanner is a class. util package used for obtaining the input of the data  types like int, double, float , char  and strings.

Line-3:

  • public class SumMul

 “SumMul” is the class-name , class is a template used to create objects & class-name first letters must be capital. It is public means we can use this outside of the package.

Line-5:

  • public static void main(String[] args)

 It is a main method in which we can execute a program.

  •  public : It is an access modifier. The main() is public because we can access main() outside of the class , if main() can’t be public then JVM(Java Virtual Machine) can’t be called main() & code can’t be executed. 
  •  Static : static is a keyword in which the main method has to be static in which JVM can load the class into memory and call the main method without creating an instance.
  •  Void : Void is a data type. It means no return type. 
  •  main(): Main is a function. 
  •  String [] args : string means collection of characters ,String[] args represents a collection of Strings that are separated by a space and can be typed into the program on the terminal directly.

Line-6:

  • int s,c,q

Here s,c,q is the variable and int (Integer) is a data type of the variable.

Line-7:

  • Scanner sc=new Scanner(System.in)

 Scanner is a class and sc is the instance of the object which is the new Scanner . System.in is an argument.

Line-8:

  • System.out.println(“Enter the value of s:”)

System is a class name and out is the instance of the system. Println is to print the new line & print the value of s.

Line-9:

  • s=sc.nextInt()

s  is a variable that we take and sc is our instance name which is created for an object and nextInt() is a method of a Scanner object that reads in a string of digits or char and converts them into an int type.

Line-10:

  • System.out.println(“Enter the value of c:”)

System is a class name and out is the instance of the system. Println is to print the new line & print the value of c.

Line-11:

  • c=sc.nextInt()

  c is a variable that we take and sc is our instance name which is created for an object and nextInt() is a method of a Scanner object that reads in a string of digits or char and converts them into an int type.

Line-12:

  • System.out.println(“Enter the value of q:”)

System is a class name and out is the instance of the system. Println is to print the new line & print the value of s.

Line-13:

  • q=sc.nextInt()

   q is a variable that we take and sc is our instance name which is created for an object and nextInt() is a method of a Scanner object that reads in a string of digits or char and converts them into an int type.

Line-14:

  •  int z= (s*s*s*s*s)+(c*c)+q

Here “z” is a variable where a given question output will be stored and int(integer) is the data type.

Line-15:

  • System.out.println(“Output of s^5+c^2+q is:\n”+z)

System is a predefined class. Out is a static variable of type printstream present in the system class. The printout shows the result.

Share Your Love
Avatar photo
SONALIN SAHOO

Myself Sonalin Shaoo. I am quite happy to contribute here some java programming content and my friends Lipsa Mohanty ,Sushil Puhan, Aswin Kumar Nayak also help me to contribute their Opinion on this .

Articles: 40

Newsletter Updates

Enter your email address below to subscribe to our newsletter