*** IMPORTANT :: It\'s all about the JAVA programing questions !! *** a) Write t
ID: 3533737 • Letter: #
Question
*** IMPORTANT :: It's all about the JAVA programing questions !! ***
a) Write the code that reads values for a,b,c and displays their sum, repeating this process as long as none of the three values are negative.
b) write the code that reads an integer number called test. With a loop, read 5 more numbers counting how many numbers are less than testValue, how many numbers are equal to test, and how many numbers are greater than test.
c) Write the code that adds the integer number 1 through 10. Print the sum as it is being generated in the loop and at the end of the program
Explanation / Answer
import java.util.Scanner;
class ABC{
public static void main(String arg[]){
Scanner in = new Scanner(System.in);
int a,b,c;
int sum=0;
System.out.println("Enter a,b,c ");
a=in.nextInt();
b=in.nextInt();
c=in.nextInt();
while(!(a<0||b<0||c<0)){
sum=a+b+c;
System.out.println("Sum of a,b,c is"+sum);
System.out.println("Enter a,b,c ");
a=in.nextInt();
b=in.nextInt();
c=in.nextInt();
}
}
}
-----------------------------------------------------------------------
import java.util.Scanner;
class Number{
public static void main(String arg[]){
Scanner in = new Scanner(System.in);
int test,equal=0,less=0,high=0;
int num[]=new int[5];
System.out.println("Enter test value: ");
test=in.nextInt();
System.out.println("Enter 5 number value: ");
for(int i=0;i<5;i++)
num[i]=in.nextInt();
for(int i=0;i<5;i++){
if(test==num[i])
equal++;
if(test>num[i])
less++;
if(test<num[i])
high++;
}
System.out.println("Number of number greater than test: "+test+"are"+high);
System.out.println("Number of number lesses than test: "+test+"are"+less);
System.out.println("Number of number equal than test: "+test+"are"+equal);
}
}
--------------------------------------------------------------------------------------
class number{
public static void main(String arg[]){
int i=0,sum=0;
for( i=1;i<11;i++)
sum=sum+i;
System.out.println("Sum of number 1 to 10 : "+sum);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.