Character Addition in Java

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:

  1. Java Program of Hy-Fly Taxi
  2. Java Program for Harima Realtor’s Example
  3. Numerology Name Checking
  4. OMR Evaluation
  5. Java program to Sum of Even Elements
  6. Alternate Number differences in Java
  7. Bike Rent Program in Java

Leave a Comment

Your email address will not be published. Required fields are marked *