




















































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
All Basic program for new student of Java Language
Typology: Study Guides, Projects, Research
1 / 60
This page cannot be seen from the preview
Don't miss anything!





















































package thisword; import java.util.Scanner; class Account { String name; void setName(String name) { this.name=name; }
String getName() { return name; } } public class ThisWord { public static void main(String[] args) { Scanner input=new Scanner(System.in); Account obj=new Account(); System.out.println("Please Enter the name"); String name=input.nextLine(); obj.setName(name); String disp=obj.getName(); System.out.printf("Name in object obj is %n%s%n",disp); } }
System.out.println("Constructing Box"); width = 10; height = 10; depth = 10; } // compute and return volume double volume() { return width * height * depth; } } public class Labb { public static void main(String[] args) { // declare, allocate, and initialize Box objects Box mybox1 = new Box(); Box mybox2 = new Box(); double vol; // get volume of first box vol = mybox1.volume(); System.out.println("Volume is " + vol); // get volume of second box vol = mybox2.volume();
System.out.println("Volume is " + vol); } }
package defaultconstractor; import java.util.Scanner; class First { int a=0; int b=0;
package labb; public class Labb { public static void main(String[] args) { int month_days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
System.out.println("April has " + month_days[3] + " days."); } }
package labb; public class Labb { public static void main(String[] args) { int twoD[][]= new int[4][5];
package labb; public class Labb { public static void main(String[] args) { int month = 4; // April String season; String season; if(month == 12 || month == 1 || month == 2) season = "Winter"; else
if(month == 3 || month == 4 || month == 5) season = "Spring"; else if(month == 6 || month == 7 || month == 8) season = "Summer"; else if(month == 9 || month == 10 || month == 11) season = "Autumn"; else season = "Bogus Month"; System.out.println("April is in the " + season + "."); } }
package labb; public class Labb { public static void main(String[] args) { int n = 10; while(n > 0) { System.out.println("tick " + n); n--; } } }
System.out.println("tick " + n); n--; } while(n > 0); } }
package labb; public class Labb
public static void main(String[] args) { int n; for(n=10; n>0; n--) System.out.println("tick " + n); } }
package enhanceforloop; public class EnhanceForLoop {
package labb; class OverloadDemo { void test() { System.out.println("No parameters"); } // Overload test for one integer parameter. void test(int a) { System.out.println("a: " + a); } // Overload test for two integer parameters. void test(int a, int b) { System.out.println("a and b: " + a + " " + b); } // overload test for a double parameter double test(double a) { System.out.println("double a: " + a); return a*a;
public class Labb { public static void main(String args[]) { OverloadDemo ob = new OverloadDemo(); double result; // call all versions of test() ob.test(); ob.test(10); ob.test(10, 20); result = ob.test(123.25); System.out.println("Result of ob.test(123.25): " + result); } }