PLEASE SOLVE AND SEND ME THE SOLUTION
WANT THE SOLUTION FROM YOUR COPY
please do it in scanner class
Answers
Hint: Use escape sequence (non graphic characters).
The Code:
public class Fruits{
public static void main(String s[]){
System.out.println("Apple.\nMango.\nGrapes.\nGuava.\nStrawberry.");
}
}
Hint: Calculate the difference between SP and CP.
The Code:
public class Profit{
public static void main(String s[]){
double SP=10000.0,CP=7000.0,P,PP;
System.out.println("SP: Rs. "+SP);
System.out.println("CP: Rs. "+CP);
P=SP-CP;
PP=P/CP * 100;
System.out.println("Gain: Rs. "+P);
System.out.println("Gain Percentage: "+PP+"%");
}
}
Answer:
Program 1:-
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
System.out.println("Apple"+"\n"+"Mango"+"\n"+"Grapes"+"\n"+"Water Melon"+"\n"+"Strawberry");
in.close();
}
}
Program 2:-
import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int cp=7000,sp=10000,p=0;
double pp=0;
p=sp-cp;
pp=p/(double)cp*100;
System.out.println("The profit="+p);
System.out.println("The profit percent="+pp+"%");
in.close();
}
}
Output is attched.
I did it in scanner class but I didn't used it as you didn't asked to input
Formula:-
P=SP-CP
profit%=p/cp*100