
part A:
import java.util.*;
import java.lang.*;
import java.io.*;
class Abc
{
public static void Armstrong()
{
int n,rem,arm; //rem for remender,arm for
armstrong
for(int i=0;i<=999;i++) //loop for finding armstrong
number b/w 0-999
{
arm=0;
n=i;
while(n>0)
{
rem=n%10;
n=n/10;
arm=arm+(rem*rem*rem);
}
if(i==arm)
System.out.println(i); //printning value if
Armstrong
}
}
public static void main (String[] args) throws
java.lang.Exception
{
Abc c = new Abc();
//declairing object of class Abc
c.Armstrong(); //calling
method
}
}
part B:
import java.util.*;
import java.lang.*;
import java.io.*;
class Abc
{
public static Boolean IsArmstrong(int i)
{
int n,rem,arm; //rem for remender,arm for
armstrong
arm=0;
n=i;
while(n>0)
{
rem=n%10;
n=n/10;
arm=arm+(rem*rem*rem);
}
if(i==arm)
return true; //if number is armstrong return
true
else
return false;
}
public static void main (String[] args) throws
java.lang.Exception
{
Abc c = new Abc();
//declairing object of class Abc
for(int i=0;i<=999;i++)
//loop for finding armstrong number b/w
0-999
{
Boolean isTrue= c.IsArmstrong(i);
//calling method IsArmstrong
if(isTrue==true) //if return true print
value
System.out.println(i);
}
}
}
Please do both parts (in Java); thanks! An Armstrong number of three digits is an integer...
Write a JAVA program to check whether a given number is an Armstrong number. An Armstrong number is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.
Java BNF How to write pseudocode for this snippet? Java code for finding a prime number public class Prime { public static void main(String[] args) { int num = 29; boolean flag = false; for(int i = 2; i <= num/2; ++i) { // condition for nonprime number if(num % i == 0) { flag = true; break; } } if (!flag) System.out.println(num + " is a prime number."); else System.out.println(num + " is not a prime number."); } }
C program--write a program to find whether the given number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is since 3**3 + 7**3 + 1**3 = 371. Output: Enter a number, or * to quit : 432 4**3 + 3**3 + 2**3 is not = 432 Enter a number, or * to quit : 371 3**3 + 7**3 + 1**3 is = 371...
C program--write a program to find whether the given number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is since 3**3 + 7**3 + 1**3 = 371. Output: Enter a number, or * to quit : 432 4**3 + 3**3 + 2**3 is not = 432 Enter a number, or * to quit : 371 3**3 + 7**3 + 1**3 is = 371...
Create a method based program to find if a number is prime and then print all the prime numbers from 1 through 500 Method Name: isPrime(int num) and returns a boolean Use for loop to capture all the prime numbers (1 through 500) Create a file to add the list of prime numbers Working Files: public class IsPrimeMethod { public static void main(String[] args) { String input; // To hold keyboard input String message; // Message...
java 1. Write a method header on line three with the following specs: Returns: a boolean Name: beTrue Parameters: none public class Main { { return true; } } 2. Write a method header on line two with the following specs: Returns: a String Name: makeCapital Parameters: a String named "name" You should not be writing code on any line other than #2 public class Main { { String ans = name.toUpperCase();...
Using C++ language please not matlab
a. Write a function, called SumOfDigits that is able to calculate the summation of a five-digit number. This function receives one integer parameter 'a', then returns the sum of 5 digits of the number. [2.5 marks] b. Write a function, called Armstrong that prints all Armstrong numbers in the range of 0 and 500. An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is...
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward, such as madam or racecar. Write a recursive method in java that accepts a integer as its argument and returns true if it is palindrome, false otherwise. public class Recursion { public static void main(String[] args) { Recursion r = new Recursion(); System.out.println(“Is 12321 a palindrome? “+ra.isPalindrome(12321)); //true } public Boolean isPalindrome(int num){ return false;...
Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please write the code according to functions assigned...
Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed for this assignment, so don't use them. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please...