have to complete the following WITHOUT using loops and arrays: Write a Java prog
ID: 3527285 • Letter: H
Question
have to complete the following WITHOUT using loops and arrays: Write a Java program which compiles and executes: ask the user for 4 integer values. Each one of these is a percent of a total cake (4 values must total 100) verify that the 4 integers of Step 1 add up to 100 (i.e: 4 values total 100%, full cake- nothing more or less) If they DO NOT add up to 100, print an error message of some form and exit the program (Hint: in main () the return; statement will cause the program to exit) Identify which slice of cake each person too assuming everyone is greedy and takes the largest slice available (person 1 will take the highest value, person 2 the second highest value etc.) THERE ARE 4 PEOPLE IN TOTAL - 1 slice/person The program should look like this: Please enter sizes of the four slices: 20 30 24 26 Person 1 took slice 2 (30%) Person 2 took slice 4 (26%) Person 3 took slice 3 (24%) Person 4 took slice 1 (20%) I use NX Client and the class name will be cakeExplanation / Answer
Please please rate me as 5 star
class SumDigit
{
public static void main(String args[])
{
int sum, i,arr[4],j;
arr[0] = Integer.parseInt(args[0]);
arr[1] = Integer.parseInt(args[1]);
arr[2] = Integer.parseInt(args[2]);
arr[3] = Integer.parseInt(args[3]);
if((arr[0]+arr[1]+arr[2]+arr[3])==100){
for(int i=0; i<4; i++){
for(int j=1; j<arr.4; j++){
if(arr[j]< arr[j-1] ){
int temp = arr[j];
arr[j] = arr[j-1];
arr[j-1] = temp;
}
}
}
System.out.println("1 person % :"+arr[0]);
System.out.println("2 person % :"+arr[1]);
System.out.println("3 person % :"+arr[2]);
System.out.println("4 person % :"+arr[3]);
}
else
{
System.out.println("error ");
return 0;
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.