Question :
Sample input 1 :
Enter : 3
Enter the sentences:
ks436
Agh73
7222
Sample output 1 :
222
240
0
Code :
import java.util.*; public class arraysquare { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Enter the customer instrution"); String str=sc.nextLine(); String w=str.substring(0,4); int weight=0,order_no=0; String order=str.substring(str.length()-3); String flavor=str.substring(4,str.length()-3); if(!(str.matches("[a-zA-z0-9]+"))) { System.out.println("Invalid Instruction"); return; } else if(w.contains("[0-9]+" )) { weight=Integer.parseInt(w); System.out.println("Invalid weight"); return; } else if(!order.contains("[0-9]+")) { System.out.println("Invalid Oreder number"); return; } else { if(weight<999) { System.out.println("Invalid Weight"); return; } double kg=(Double.parseDouble(w))/1000; System.out.println("Cake weight is "+kg+"kg"); System.out.println("Cake Flavor is "+flavor); System.out.println("Cake No is "+order); double price=450*kg; System.out.println("Price is "+String.format("%.2f",price)); } } }
Recommended:
- Java Program of Hy-Fly Taxi
- Java Program for Harima Realtor’s Example
- Numerology Name Checking
- OMR Evaluation
- Java program to Sum of Even Elements
- Alternate Number differences in Java
- Bike Rent Program in Java