0
My answer is compatible to the task? anyone help me please
(this is the task) https://code.sololearn.com/cCw03Khf2C7M/?ref=app (my answer) https://code.sololearn.com/cV1qs35vBtfX/?ref=app
9 Respuestas
+ 2
Task has 2 inputs
* a double value
* a string of values in format : "{hours} {path} {price}"
But you are taking 4 double values!!.
What's your idea there?..
add also your error details...
+ 1
lets go step by step:
Ex: 8 ABMRB 24.50
Run loop 8 times through 'ABMRB', circularly, if path=='B' it's a battle else no
You get 3 Battles = 3, at 2(B), at 5(B), at 7(B)..
Battles *24.50 = 73.50
If it is greater than 1st input, print profit.
Else loss
Format Output as mentioned in description..
You can loop trough string by
for(int I=0; i< 8; I++)
if( pat[1].charAt(i%5) == 'B')
Battle++;
0
my idea have 4 inputs but idk how I put the 2 inputs in this problem
0
can you try this problem sir
0
First input read by sc.nextDouble();
Next read inputs by sc.next(); into a 3 strings or into a array of strings.
You can also read entire line by nextLine() and split by space into string of array.. But for simplicity now, use first way.. Then go on to next step.
0
how can I compute the bottle I earn in that day
public static void main(String[] args) {
String [] pat = {"hour","location","price"};
double daily;
Scanner sc = new Scanner(System.in);
System.out.println("Input Daily Expenses: ");
daily = sc.nextDouble();
System.out.println("Input the 'Hour' 'Path' 'Price'");
pat[0] = sc.next();
pat[1] = sc.next();
pat[2] = sc.next();
0
Jaykrishna sir can show your code,
0
sir can you show your code I've already work this but they give me some errors
0
//Edited your code just to get a sample output for input : 25 8 ABCB 24.5
import java.util.Scanner;
public class pract1 {
public static void main(String[] args){
double tot2, cost, hour, price;
Scanner sc = new Scanner(System.in);
System.out.println("Enter Your Daily Expenses:");
cost = sc.nextDouble();
System.out.println("Enter the Bottle hours :");
hour = sc.nextDouble();
System.out.println("Path: ");
String path = sc.next();
System.out.println("Meals:");
price = sc.nextDouble();
int Battles=0;
for(int i=0; i< hour; i++)
if( path.charAt(i%5) == 'B')
Battles++;
tot2 = Battles * price;
if(tot2>cost){
System.out.println("Good Earnings. Extra money in that day: "+ (tot2-cost));}
else{
System.out.println("Hard times. Money needed: "+Math.abs(cost-tot2));
}}
}