Share on Google+Share on Google+

mubashir
begineer
1 Answer(s)      6 years and 6 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

Ads

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
Tutorials   
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized

Ads

 
Advertisement null

Ads