Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


mubashir
begineer
1 Answer(s)      4 years and 2 months ago
Posted in : Java Beginners


ALL program are written in java!!!

Q.1.write a program which have 4 integer value is int a=2;int b=4;intc=5;intd=6; and its check all four integer number that which have maximum value and which have smaller.??

Q.2.write a program in whch class have two integer value and their value is 8 and 10 which is hard coted and have 6 method . first method .done a sum of both value and return it. second method done multiplication and return it. 3rd method take modulus and also check which value is greater and which is smaller and also return it. 4th method do division and also check which value is greater and which is smaller and also return it. 5th methid do subtraction and also check which value is greater and which is smaller and also return it. 6th method is check which value is great which integer value we take it in above program which is hardcoted


Advertisement
View Answers

October 25, 2010 at 3:02 PM


Hi Friend,

Try the following codes:

1)

public class MaxMin {
 public static void main(String[] args) {
     int a=2;
     int b=4;
     int c=5;
     int d=6;
      int arr[]={a,b,c,d};
    int max = arr[0];
    int min = arr[0];

        for(int i=1;i<arr.length;i++){
           if (arr[i] > max) {
           max = arr[i];
            }
        }
        System.out.println("Largest Number: "+max);
        for (int i=1; i<arr.length; i++) {
            if (arr[i]< min) {
                min = arr[i];
            }
        }
        System.out.println("Smallest Number: "+min);
     }
}

2)

class Calculate{
    int i,j;
    Calculate(int i,int j){
    this.i=i;
    this.j=j;
}
public int add(){
    return i+j;
}
public int multiply(){
    return i*j;
}
public int subtract(){
    int result=0;
    if(i>j){
    result= i-j;
    }
    else{
    result= j-i;
    }
    return result;
}
public int divide(){
    int result=0;
    if(i>j){
    result= i/j;
    }
    else{
    result= j/i;
    }
    return result;
}
public int modulus(){
    int result=0;
    if(i>j){
    result= i%j;
    }
    else{
    result= j%i;
    }
    return result;
}
public int check(){
    int greater=0;
    if(i>j){
        greater=i;
    }
    else{
        greater=j;
    }
    return greater;
}
    public static void main(String[] args){
        Calculate c=new Calculate(8,10);
        System.out.println("Addition= "+c.add());
        System.out.println("Subtraction= "+c.subtract());
        System.out.println("Multiplication= "+c.multiply());
        System.out.println("Division= "+c.divide());
        System.out.println("Modulus= "+c.modulus());
        System.out.println("Greater value= "+c.check());
    }
}

Thanks



Related Tutorials/Questions & Answers:
Advertisements
Begineer in coding please help me
Begineer in coding please help me  I have Person class{ int pid; String Pname; //and have a Address filed of type Address not String!!! Address add; } i know i should create a class Address{ String state; Sting country
Begineer Help Help Please Thanks A million ) I am using Jcreator
Begineer Help Help Please Thanks A million ) I am using Jcreator  System.out.println(" Income Statement"); System.out.print("Year
set java exe file as background - Java Beginners
set java exe file as background  hi frenz, i am begineer to java. in my application i have a one exe file. now i wanna the file... is closed then v don't continue that application.. can u tell me how java exe file set
about java - Java Beginners
about java  hello, being a begineer in Java i would like know that as we read the value entered by user through cin>> in c++ how we did it with java.  Hi Friend, There are lot of ways to input data.You can use
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java begineer programmer i recently started developing programes on NetBeans using the GUI as it is more reliable and efficent - the current program that i am working
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java begineer programmer i recently started developing programes on NetBeans using the GUI as it is more reliable and efficent - the current program that i am working
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java begineer programmer i recently started developing programes on NetBeans using the GUI as it is more reliable and efficent - the current program that i am working
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java begineer programmer i recently started developing programes on NetBeans using the GUI as it is more reliable and efficent - the current program that i am working
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java begineer programmer i recently started developing programes on NetBeans using the GUI as it is more reliable and efficent - the current program that i am working
Till Slip Program Error Free - No Main Method
Till Slip Program Error Free - No Main Method  Hi there i am a java begineer programmer i recently started developing programes on NetBeans using the GUI as it is more reliable and efficent - the current program that i am working
 

 

 

DMCA.com