Professional Documents
Culture Documents
myfirstjava;
2.package com.java.myfirstjava;
import java.util.*;
public class HelloJava {
3.package javaf;
}
}
/*
i=0 0<=3 0 i=0+1=1 i=i+1
i=4 4<=3
*/
4.package javaf;
5.package javaf;
cars[0] = "Opel";
System.out.println(cars[0]);
System.out.println(cars.length);
System.out.println(i);
}
for (int i : a) {
System.out.println(i);
}
6.package com.java.array;
For example:
The array int[][] x = new int[10][20] can store a total of (10*20) = 200 elements.
Similarly, array int[][][] x = new int[5][10][20] can store a total of (5*10*20) =
1000 elements.
The elements of a 2D array are arranged in rows and columns, and the new operator
for 2D arrays specifies both the number of rows and the number of columns. For
example,
int[][] A;
A = new int[3][4];
This creates a 2D array of int that has 12 elements arranged in 3 rows and 4
columns.
// SAMPLE
public class Array3 {
i=2 2<2
*/
System.out.println();
}
}}
6.import java.util.*;
import java.io.*;
class Main{
public static void main(String[] args) throws Exception{
double br,tr,food,logic;
double a,b,c,d,total;
Scanner sc=new Scanner(System.in);
System.out.println("Enter branding expenses");
br=sc.nextDouble();
System.out.println("Enter travel expenses");
tr=sc.nextDouble();
System.out.println("Enter food expenses");
food=sc.nextDouble();
System.out.println("Enter logistics expenses");
logic=sc.nextDouble();
total=br+tr+food+logic;
System.out.println("Total expenses: Rs."+String.format("%.2f",total));
a=(br/total)*100;
b=(tr/total)*100;
c=(food/total)*100;
d=(logic/total)*100;
System.out.println("Branding expenses percentage: "+String.format("%.2f",a)
+"%");
System.out.println("Travel expenses percentage: "+String.format("%.2f",b)
+"%");
System.out.println("Food expenses percentage: "+String.format("%.2f",c)
+"%");
System.out.println("Logistics expenses percentage:
"+String.format("%.2f",d)+"%");
}
}