QuestionAsk Questions?

Q.1.write a program which have 4 integer hard value 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 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

View Answers

October 23, 2010 at 3:03 PM

Hi Friend,

Here is your first part:

import java.util.*; public class MaxMin { public static void main(String[] args) { Scanner input = new Scanner(System.in); int maxNumber = Integer.MIN_VALUE; int minNumber = Integer.MAX_VALUE; System.out.println("Enter 4 numbers:"); for(int i=1;i<=4;i++){ int number = input.nextInt(); if (number > maxNumber) { maxNumber = number; } if (number < minNumber) { minNumber = number; } } System.out.println("Maximum Number = " + maxNumber); System.out.println("Minimum Number= " + minNumber); } }

Thanks

October 23, 2010 at 3:16 PM

Hi Friend,

Here is your second part:

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(2,7); 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