write a program to print golbash number in java
Answers
Answered by
0
Program in Java to print an integer (entered by the user):-
import java.util.Scanner;
public class HelloWorld {
public static void main(String[] args) {
// Creates a reader instance which takes // input from standard input - keyboard Scanner reader = new Scanner(System.in); System.out.print("Enter a number: ");
// nextInt() reads the next integer from the keyboard int number = reader.nextInt();
// println() prints the following line to the output screen System.out.println("You entered: " + number); } }
Output:-
Enter a number: 10
You entered: 10
HOPE IT HELPS!!
import java.util.Scanner;
public class HelloWorld {
public static void main(String[] args) {
// Creates a reader instance which takes // input from standard input - keyboard Scanner reader = new Scanner(System.in); System.out.print("Enter a number: ");
// nextInt() reads the next integer from the keyboard int number = reader.nextInt();
// println() prints the following line to the output screen System.out.println("You entered: " + number); } }
Output:-
Enter a number: 10
You entered: 10
HOPE IT HELPS!!
Answered by
1
Theory:
=> A Goldbach number is a positive even integer that can be expressed as the sum of two prime numbers.
=> Every even number above 2 is though to be a Goldbach number.
Information:
=> This program first finds a prime number, then finds another prime number greater than equal to the first one, and checks if their sum is equal to the original number.
=> It repeats this process, if the number is found to be the sum of two primes, then it increases the value of variable counter from zero to 1.
=> Otherwise it repeats the process.
=> Another boolean return type method has been used to check if a number is prime or not.
Program:
=> I have attached the .java file and another pdf file for screenshots and an image showing the output on bluej .
Attachments:
Similar questions