In C#: int[] list = new int[] { 1 , 2, 3, 4}; int highest = int.MinValue; foreach(int i in list) { if(i > highest) { highest = i; } } Console.WriteLine(highest.ToString() + " is the highest number");
import java.io.*;class MagicNumber{public int divide(int x){int a,b=0;for(int i=x;i>0;i/=10){a=i%10;b+=a;}return b;}protected static void main()throws IOException{BufferedReader in=new BufferedReader(new InputStreamReader(System.in));System.out.print("Enter the number: ");int a =Integer.parseInt(in.readLine()),b=0,x=1;MagicNumber l=new MagicNumber();do{if(x==1){b=l.divide(a); x++;}else{b=l.divide(b);}}while((b/10)>0);if(b==1)System.out.print("Magic Number!!!!!");elseSystem.out.print("Not a Magic Number!!!!!");}}
public int findSum(int n1, int n2) { return n1 + n2; }
class Count { public static void main(String args[]) { int i,c=0; int n=args.length; System.out.println("length is"+n); for(i=0;i<args.length;i++) { System.out.println(args[i]); c++; } System.out.println("number of words="+c); } }
class Fibonacci { public static void main(String args[]) { System.out.println("enter the number upto u want"); int number=Integer.parseInt(args[0]); int a=0,b=1,c=0; System.out.print(a+" "+b); for(int i=1;i<=number;i++) { c=a+b; System.out.print(c+" "); a=b; b=c; } } } the number are given to the run time where are print the series eg: 5 0 1 1 2 3 5 8 13................
public class FindLeastAndGreatest { public static void main(String[] args) { // number can't be equal with each other int a = 7; int b = 7; int c = 6; System.out.println(least(a,b,c)); System.out.println(greatest(a,b,c)); } public static int least(int a, int b, int c) { int least = 0; if(a < b && a < c) { least = a; } else if(b < a && b < c) { least = b; } else { least = c;} return least; } public static int greatest(int a, int b, int c) { int greatest = 0; if(a > b && a > c) { greatest = a; } else if(b > a && b > c) { greatest = b; } else { greatest = c;} return greatest; } }
In C#: int[] list = new int[] { 1 , 2, 3, 4}; int highest = int.MinValue; foreach(int i in list) { if(i > highest) { highest = i; } } Console.WriteLine(highest.ToString() + " is the highest number");
import java.io.*;class MagicNumber{public int divide(int x){int a,b=0;for(int i=x;i>0;i/=10){a=i%10;b+=a;}return b;}protected static void main()throws IOException{BufferedReader in=new BufferedReader(new InputStreamReader(System.in));System.out.print("Enter the number: ");int a =Integer.parseInt(in.readLine()),b=0,x=1;MagicNumber l=new MagicNumber();do{if(x==1){b=l.divide(a); x++;}else{b=l.divide(b);}}while((b/10)>0);if(b==1)System.out.print("Magic Number!!!!!");elseSystem.out.print("Not a Magic Number!!!!!");}}
public class TwistedPrime { public static void main(int n)//Enter a number { int num,s=0,c=0,d; num=n; while(n>0) { d=n%10; s=s*10+d; n=n/10; { for(int i=1;i<s;i++) { if(s%i==0) c++; } } } if(c==1) System.out.print("Number is Twisted Prime"); else System.out.print("Number is not T.P."); } }
C# function or a method can be called as described below: -Public class myClass{int num;public myClass(int n){num=n;}public int returnSquare(){return num*num;}}Public class startUpClass{Public static void Main(StringArgs ar){myClass obj=new myClass(12);int result=obj.returnSquare();}}
public int findSum(int n1, int n2) { return n1 + n2; }
int max (int a, int b) { return a<b?b:a; } int max3 (int a, int b, int c) { return max (max (a, b), c); }
class Count { public static void main(String args[]) { int i,c=0; int n=args.length; System.out.println("length is"+n); for(i=0;i<args.length;i++) { System.out.println(args[i]); c++; } System.out.println("number of words="+c); } }
Yes, it is possible to do this. Consider the following example that returns an instance of class C from the sum of two instances of class A. #include <iostream> class A { public: A(int i=0):m_data(i){} int m_data; }; class C { public: C(int i=0):m_data(i){} int m_data; }; C operator+(const A&a,const A&b) { return(C(a.m_data+b.m_data)); } int main( void ) { A a(5); A b(6); C c=a+b; std::cout<<"c.m_data="<<c.m_data<<std::endl; return(0); }
class Fibonacci { public static void main(String args[]) { System.out.println("enter the number upto u want"); int number=Integer.parseInt(args[0]); int a=0,b=1,c=0; System.out.print(a+" "+b); for(int i=1;i<=number;i++) { c=a+b; System.out.print(c+" "); a=b; b=c; } } } the number are given to the run time where are print the series eg: 5 0 1 1 2 3 5 8 13................
// Print prime number series. class prime { void main () { int i = 1; int C = 0; int n = 1; int X = 0; while (X != 1000) { if ( n % i n ) { C = 0; n++ ; i = 0; } } i++ ; } } }
import java.io.*;class PerfectPalindrome{private boolean per(int a){int b=0,c=1;for(;c0;b/=10){int d=b%10;c=(c*10)+d;}if(c==a)return true;elsereturn false;}public static void main()throws IOException{BufferedReader in=new BufferedReader(new InputStreamReader(System.in));System.out.println("1. Find a number is a perfect one or not !");System.out.println("2. Find a number is a palindrome or not !");System.out.print("\nEnter your Choice: ");int a=Integer.parseInt(in.readLine()),c;System.out.print("Enter the Number: ");c=Integer.parseInt(in.readLine());boolean b;PerfectPalindrome e=new PerfectPalindrome();switch(a){case 1: b=e.per(c);if(b==true)System.out.print("It is a Perfect Number !");elseSystem.out.print("It is not a Perfect Number !");break;case 2: b=e.pal(c);if(b==true)System.out.print("It is a Palindrome Number !");elseSystem.out.print("It is not a Palindrome Number !");break;default: System.out.print("SORRY!! Wrong Choice!");