Search Your Topic

config
Anish Sir

Anish Sir

"I am delighted once again to pen the welcome note to the Tosh!Yas Technologies ."

 Call +91 74 88 34 7779  | Email : anishsingh@live.com

Website URL: http://toshiyas.in
Friday, 07 December 2018 07:50

Java program to check Spy number

Spy Number

A number is a Spy number, if sum and product of all digits are equal.

Example:

Number 123 is a Spy number, sum of its digits is 6 (1+2+3 =6) and product of its digits is 6 (1x2x3 = 6), sum and product are same, thus, 123 is a spy number.

import java.util.Scanner;

public class SpyNumber 
{
	public static void main(String[] args)
	{   
		int n,product=1,sum=0;
		int ld;

		// create object of scanner.
		Scanner sc = new Scanner(System.in);

		// you have to enter number here.
		System.out.print("Enter the number :" );

		// read entered number and store it in "n".
		n=sc.nextInt();

		// calculate sum and product of the number here.
		while(n>0)
		{
			ld=n%10;
			sum=sum+ld;
			product=product*ld;
			n=n/10;
		}

		// compare the sum and product.
		if(sum==product)
			System.out.println("Given number is spy number");
		else
			System.out.println("Given number is not spy number");
	}
}

Output
First run:
Enter the number :1124
Given number is spy number

Second run:
Enter the number :1123
Given number is not spy number

Program to check Spy number in java

This program checks if a number entered is a Neon Number or not, in JAVA.

A number is said to be a Neon Number if the sum of digits of the square of the number is equal to the number itself.

Example- 9 is a Neon Number. 9*9=81 and 8+1=9.Hence it is a Neon Number.

Program - 

import java.util.*;
public class NeonNumber
{
    public static void main(String args[])
    {
        Scanner ob=new Scanner(System.in);
        System.out.println("Enter the number to be checked.");
        int num=ob.nextInt();
        int square=num*num;
        int sum=0;
        while(square!=0)//Loop to find the sum of digits.
        {
            int a=square%10;
            sum=sum+a;
            square=square/10;
        }
        if(sum==num)
        {
            System.out.println(num+" is a Neon Number.");
        }
        else
        {
            System.out.println(num+" is not a Neon Number.");
        }
    }
}

Description - 

The number is entered through Scanner class and then its square is taken by multiplying the number 2 times.After that we find the sum of digits of the square and check if the number is equal to the sum of digits of square of the number.

Write a Java program to classify Abundant, deficient and perfect number (integers) between 1 to 10,000.

In number theory, an abundant number is a number for which the sum of its proper divisors is greater than the number itself.
Example :
The first few abundant numbers are:
12, 18, 20, 24, 30, 36, 40, 42, 48, 54, 56, 60, 66, 70, 72, 78, 80, 84, 88, 90, 96, 100, 102,…
The integer 12 is the first abundant number. Its proper divisors are 1, 2, 3, 4 and 6 for a total of 16.
Deficient number: In number theory, a deficient number is a number n for which the sum of divisors σ(n)<2n, or, equivalently, the sum of proper divisors (or aliquot sum) s(n)<n. The value 2n − σ(n) (or n − s(n)) is called the number's deficiency.
As an example, divisors of 21 are 1, 3 and 7, and their sum is 11. Because 11 is less than 21, the number 21 is deficient. Its deficiency is 2 × 21 − 32 = 10.
The first few deficient numbers are:
1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 19, 21, 22, 23, 25, 26, 27, 29, 31, 32, 33, …….
Perfect number: In number system, a perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself.
Equivalently, a perfect number is a number that is half the sum of all of its positive divisors (including itself) i.e. σ1(n) = 2n.
The first perfect number is 6. Its proper divisors are 1, 2, and 3, and 1 + 2 + 3 = 6. Equivalently, the number 6 is equal to half the sum of all its positive divisors: ( 1 + 2 + 3 + 6 ) / 2 = 6. The next perfect number is 28 = 1 + 2 + 4 + 7 + 14. This is followed by the perfect numbers 496 and 8128.

Sample Solution:

Java Code:

import static java.util.stream.LongStream.rangeClosed;
public class Exercise2 {

public static void main(String[] args) {
int count_Deficient_no = 0;
int count_Perfect_no = 0;
int count_Abundant_no = 0;

for (long i = 1; i <= 10_000L; i++) {
long sum = proper_Divs_Sum(i);
if (sum < i)
count_Deficient_no++;
else if (sum == i)
count_Perfect_no++;
else
count_Abundant_no++;
}
System.out.println("Number Counting [(integers) between 1 to 10,000]: ");
System.out.println("Deficient number: " + count_Deficient_no);
System.out.println("Perfect number: " + count_Perfect_no);
System.out.println("Abundant number: " + count_Abundant_no);
}
public static Long proper_Divs_Sum(long num) {
return rangeClosed(1, (num + 1) / 2).filter(i -> num % i == 0 && num != i).sum();
}
}
 
Sample Output:
Number Counting [(integers) between 1 to 10,000]:
Deficient number: 7508 
Perfect number: 4   
Abundant number: 2488

 

Tuesday, 28 August 2018 05:11

Hello, world!

Tuesday, 28 August 2018 05:04

JavaScript Fundamentals

  1. Hello, world!
  2. Code structure
  3. The modern mode, "use strict"
  4. Variables
  5. Data types
  6. Type Conversions
  7. Operators
  8. Comparisons
  9. Interaction: alert, prompt, confirm
  10. Conditional operators: if, '?'
  11. Logical operators
  12. Loops: while and for
  13. The "switch" statement
  14. Functions
  15. Function expressions and arrows
  16. JavaScript specials
Tuesday, 28 August 2018 04:50

JavaScript

This topic provides a step-by-step introduction to building, debugging, and publishing a simple .NET Core console application using C# in Visual Studio 2017. Visual Studio 2017 provides a full-featured development environment for building .NET Core applications. As long as the application doesn't have platform-specific dependencies, the application can run on any platform that .NET Core targets and on any system that has .NET Core installed.

A simple Hello World application

Begin by creating a simple "Hello World" console application. Follow these steps:

  1. Launch Visual Studio 2017. Select File > New > Project from the menu bar. In the New Project* dialog, select the Visual C# node followed by the .NET Core node. Then select the Console App (.NET Core) project template. In the Name text box, type "HelloWorld". Select the OK button.

    New Project dialog with Console App selected

  2. Visual Studio uses the template to create your project. The C# Console Application template for .NET Core automatically defines a class, Program, with a single method, Main, that takes a String array as an argument. Main is the application entry point, the method that's called automatically by the runtime when it launches the application. Any command-line arguments supplied when the application is launched are available in the args array.

    Visual Studio and the new HelloWorld project

    The template creates a simple "Hello World" application. It calls the Console.WriteLine(String) method to display the literal string "Hello World!" in the console window. By selecting the HelloWorld button with the green arrow on the toolbar, you can run the program in Debug mode. If you do, the console window is visible for only a brief time interval before it closes. This occurs because the Mainmethod terminates and the application ends as soon as the single statement in the Main method executes.

  3. To cause the application to pause before it closes the console window, add the following code immediately after the call to the Console.WriteLine(String) method:

    C#
    Console.Write("Press any key to continue...");
    Console.ReadKey(true);
    

    This code prompts the user to press any key and then pauses the program until a key is pressed.

  4. On the menu bar, select Build > Build Solution. This compiles your program into an intermediate language (IL) that's converted into binary code by a just-in-time (JIT) compiler.

  5. Run the program by selecting the HelloWorld button with the green arrow on the toolbar.

    Console window showing Hello World Press any key to continue

  6. Press any key to close the console window.

Enhancing the Hello World application

Enhance your application to prompt the user for their name and display it along with the date and time. To modify and test the program, do the following:

  1. Enter the following C# code in the code window immediately after the opening bracket that follows the static void Main(string[] args) line and before the first closing bracket:

    C#
    Console.WriteLine("\nWhat is your name? ");
    var name = Console.ReadLine();
    var date = DateTime.Now;
    Console.WriteLine($"\nHello, {name}, on {date:d} at {date:t}!");
    Console.Write("\nPress any key to exit...");
    Console.ReadKey(true);
    

    This code replaces the existing Console.WriteLine, Console.Write, and Console.ReadKey statements.

    Visual Studio Program c-sharp file with updated Main method

    This code displays "What is your name?" in the console window and waits until the user enters a string followed by the Enter key. It stores this string into a variable named name. It also retrieves the value of the DateTime.Now property, which contains the current local time, and assigns it to a variable named date. Finally, it uses an interpolated string to display these values in the console window.

  2. Compile the program by choosing Build > Build Solution.

  3. Run the program in Debug mode in Visual Studio by selecting the green arrow on the toolbar, pressing F5, or choosing the Debug > Start Debugging menu item. Respond to the prompt by entering a name and pressing the Enter key.

    Console window with modified program output

  4. Press any key to close the console window.

C# is an elegant and type-safe object-oriented language that enables developers to build a variety of secure and robust applications that run on the .NET Framework. You can use C# to create Windows client applications, XML Web services, distributed components, client-server applications, database applications, and much, much more. Visual C# provides an advanced code editor, convenient user interface designers, integrated debugger, and many other tools to make it easier to develop applications based on the C# language and the .NET

     Note

The Visual C# documentation assumes that you have an understanding of basic programming concepts. If you are a complete beginner, you might want to explore Visual C# Express, which is available on the Web. You can also take advantage of books and Web resources about C# to learn practical programming skills.

C# Language

C# syntax is highly expressive, yet it is also simple and easy to learn. The curly-brace syntax of C# will be instantly recognizable to anyone familiar with C, C++ or Java. Developers who know any of these languages are typically able to begin to work productively in C# within a very short time. C# syntax simplifies many of the complexities of C++ and provides powerful features such as nullable value types, 

As an object-oriented language, C# supports the concepts of encapsulation, inheritance, and polymorphism. All variables and methods, including the Main method, the application's entry point, are encapsulated within class definitions. A class may inherit directly from one parent class, but it may implement any number of interfaces. Methods that override virtual methods in a parent class require the override keyword as a way to avoid accidental redefinition. In C#, a struct is like a lightweight class; it is a stack-allocated type that can implement interfaces but does not support inheritance.

In addition to these basic object-oriented principles, C# makes it easy to develop software components through several innovative language constructs, including the following:

  • Encapsulated method signatures called delegates, which enable type-safe event notifications.

  • Properties, which serve as accessors for private member variables.

  • Attributes, which provide declarative metadata about types at run time.

  • Inline XML documentation comments.

  • Language-Integrated Query (LINQ) which provides built-in query capabilities across a variety of data sources.

If you have to interact with other Windows software such as COM objects or native Win32 DLLs, you can do this in C# through a process called "Interop." Interop enables C# programs to do almost anything that a native C++ application can do. C# even supports pointers and the concept of "unsafe" code for those cases in which direct memory access is absolutely critical.

The C# build process is simple compared to C and C++ and more flexible than in Java. There are no separate header files, and no requirement that methods and types be declared in a particular order. A C# source file may define any number of classes, structs, interfaces, and events.

.NET Framework Platform Architecture

C# programs run on the .NET Framework, an integral component of Windows that includes a virtual execution system called the common language runtime (CLR) and a unified set of class libraries. The CLR is the commercial implementation by Microsoft of the common language infrastructure (CLI), an international standard that is the basis for creating execution and development environments in which languages and libraries work together seamlessly.

Source code written in C# is compiled into an intermediate language (IL) that conforms to the CLI specification. The IL code and resources, such as bitmaps and strings, are stored on disk in an executable file called an assembly, typically with an extension of .exe or .dll. An assembly contains a manifest that provides information about the assembly's types, version, culture, and security requirements.

When the C# program is executed, the assembly is loaded into the CLR, which might take various actions based on the information in the manifest. Then, if the security requirements are met, the CLR performs just in time (JIT) compilation to convert the IL code to native machine instructions. The CLR also provides other services related to automatic garbage collection, exception handling, and resource management. Code that is executed by the CLR is sometimes referred to as "managed code," in contrast to "unmanaged code" which is compiled into native machine language that targets a specific system. The following diagram illustrates the compile-time and run-time relationships of C# source code files, the .NET Framework class libraries, assemblies, and the CLR.

From C# source code to machine execution

Language interoperability is a key feature of the .NET Framework. Because the IL code produced by the C# compiler conforms to the Common Type Specification (CTS), IL code generated from C# can interact with code that was generated from the .NET versions of Visual Basic, Visual C++, or any of more than 20 other CTS-compliant languages. A single assembly may contain multiple modules written in different .NET languages, and the types can reference each other just as if they were written in the same language.

In addition to the run time services, the .NET Framework also includes an extensive library of over 4000 classes organized into namespaces that provide a wide variety of useful functionality for everything from file input and output to string manipulation to XML parsing, to Windows Forms controls. The typical C# application uses the .NET Framework class library extensively to handle common "plumbing" chores.

Wednesday, 25 April 2018 10:23

C#

Monday, 02 April 2018 12:36

family and relationships

Here are some expressions commonly used in discussing family and relationships matters.

aunt
 the sister of someone´s father or mother, or the wife of someone´s uncle
 चाची
cousin 
a child of a person´s aunt or uncle
 चचेरा भाई
daughter
 your female child
 बेटी
daughter-in-law
your son´s wife
 बहुॅ
ex-husband 
a man who was formerly a certain woman´s husband
 पूर्व पति
ex-wife
a woman who was formerly a particular man´s wife
 पूर्व पत्नी
father 
a male parent
 पिता
father-in-law 
the father of the person you are married to
 ससुर
first cousin
the child of one's aunt or uncle
 चचेरा भाई
first cousin once removed 
your mother's first cousin; the words "once removed" mean that there is a difference of one generation
 
foster parent
a person who acts as parent and guardian for a child in place of the child´s natural parents but without legally adopting the child
 पालक माता पिता
foster-child
  a child who is raised by foster parents
 धाय पालित संतान
godparent
a person who agrees to take care of a child if something were to happen to their parents or guardians
 
grandchild
the child of a person´s son or daughter
पोता 
granddaughter
the daughter of a person´s son or daughter
पोती
 
grandson
 the son of a person´s son or daughter
 पोता
great grandchild
a child of your grandson or granddaughter
 पर पोता
husband
a married man; a woman´s partner in marriage, hubby
 पति
in-law
relative by marriage
 ससुराल वाले
mother
a woman who has given birth to a child; female parent
 मां
nephew 
a son of your brother or sister
 भतीजा
niece
a daughter of your brother or sister
 भांजी
parent 
a father or mother
 माता-पिता
second cousin
person in your family who has the same great-grandparents as yousister - a girl or woman who has the same parents as another person
 
son
a male child
 बेटा
son-in-law 
the husband of your daughter
 दामाद
step-parent
 the man or woman who is married to someone´s mother or father but who is not their real father or mother
 सौतेले माँ बाप
twin 
either of two offspring born at the same time from the same pregnancy
 जुड़वां
uncle
the brother of your father or mother; the husband of your aunt
 चाचा
widow
a woman whose husband is dead especially one who has not remarried
विधवा
 
widower 
a man whose wife is dead especially one who has not remarried
 विधुर
wife
a man´s partner in marriage
 पत्नी
     

MARITAL RELATIONSHIPS

divorced - married in the past but not now married

divorcee - someone who is divorced and who has not married again

engaged - having formally agreed to marry

separated - living apart but not divorced

single - not married, or not having a romantic relationship with someone

widowed - describes a person whose husband or wife has died 


FAMILY and RELATIONSHIPS - verbs

get divorced from
get engaged to
get married to
get on well with somebody
marry someone
start a relationship with someone
end a relationship with someone

Page 1 of 34

Java Training

Facebook